Module: Ohm::Utils

Defined in:
lib/ohm-zset.rb

Class Method Summary collapse

Class Method Details

.proc_to_string(function) ⇒ Object



32
33
34
# File 'lib/ohm-zset.rb', line 32

def proc_to_string(function)
  function.to_source
end

.score_field_to_string(score_field) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ohm-zset.rb', line 40

def score_field_to_string(score_field)
  string_list = []

  lambda_function = score_field.each do |field|
    break field if field.is_a? Proc

    string_list.push(field.to_s)

    break lambda{ |x| x.to_i } if field == score_field.last
  end

  string_list.push Ohm::Utils.proc_to_string(lambda_function)
  string_list.join(":")
end

.string_to_proc(function) ⇒ Object



36
37
38
# File 'lib/ohm-zset.rb', line 36

def string_to_proc(function)
  eval function
end

.string_to_score_field(score_field) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/ohm-zset.rb', line 55

def string_to_score_field(score_field)
  string_list = score_field.split(":")
  return_list = []

  string_list.each do |field|
    if field.include? 'proc'
      return_list.push Ohm::Utils.string_to_proc field
    else
      return_list.push field.to_sym
    end
  end

  return_list
end