Class: Billing::FieldsList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
app/models/billing/fields_list.rb

Overview

collection of fields, fields details are stored in config/billing/fields.yml file

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fields_details = {}) ⇒ FieldsList

Returns a new instance of FieldsList


8
9
10
# File 'app/models/billing/fields_list.rb', line 8

def initialize(fields_details = {})
  @fields = create_fields(fields_details)
end

Instance Attribute Details

#fieldsObject

Returns the value of attribute fields


6
7
8
# File 'app/models/billing/fields_list.rb', line 6

def fields
  @fields
end

Instance Method Details

#create_fields(fields = {}) ⇒ Object


25
26
27
28
29
30
31
# File 'app/models/billing/fields_list.rb', line 25

def create_fields(fields = {})
  [].tap do |fields_list|
    fields.each do |key, value|
      fields_list << Field.new(value.merge(name: key))
    end
  end
end

#each(&block) ⇒ Object


12
13
14
# File 'app/models/billing/fields_list.rb', line 12

def each(&block)
  fields.each(&block)
end

#next_field(field) ⇒ Object


21
22
23
# File 'app/models/billing/fields_list.rb', line 21

def next_field(field)
  find { |next_field| next_field.order == field.order + 1 }
end

#spaces_to_next_field(field) ⇒ Object


16
17
18
19
# File 'app/models/billing/fields_list.rb', line 16

def spaces_to_next_field(field)
  next_field = next_field(field)
  next_field.position_from - field.position_to - 1 if next_field.present?
end