Class: Hyperion::Format

Inherits:
Object
  • Object
show all
Defined in:
lib/hyperion/format.rb

Class Method Summary collapse

Class Method Details

.format_field(field) ⇒ Object



12
13
14
# File 'lib/hyperion/format.rb', line 12

def format_field(field)
  Util.snake_case(field.to_s).to_sym
end

.format_kind(kind) ⇒ Object



8
9
10
# File 'lib/hyperion/format.rb', line 8

def format_kind(kind)
  Util.snake_case(kind.to_s)
end

.format_operator(operator) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/hyperion/format.rb', line 35

def format_operator(operator)
  case operator
  when '=', 'eq'
    '='
  when '!=', 'not'
    '!='
  when '<', 'lt'
    '<'
  when '>', 'gt'
    '>'
  when '<=', 'lte'
    '<='
  when '>=', 'gte'
    '>='
  when 'contains?', 'contains', 'in?', 'in'
    'contains?'
  end
end

.format_order(order) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/hyperion/format.rb', line 25

def format_order(order)
  order.to_sym
  case order
  when :desc, 'desc', 'descending'
    :desc
  when :asc, 'asc', 'ascending'
    :asc
  end
end

.format_record(record) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/hyperion/format.rb', line 16

def format_record(record)
  record = record.reduce({}) do |new_record, (field_name, value)|
    new_record[Util.snake_case(field_name.to_s).to_sym] = value
    new_record
  end
  record[:kind] = format_kind(record[:kind])
  record
end