Class: SSO::Elements::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/sso/elements/config.rb

Constant Summary collapse

CFG_AVAIL =
{
  150 => 'PW_1.0.2_v150.cfg',
  152 => 'PW_1.0.2_v152.cfg'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



19
20
21
22
23
24
# File 'lib/sso/elements/config.rb', line 19

def initialize
  @offsets = []
  @fields = []
  @types = []
  @values = []
end

Instance Attribute Details

#fieldsObject

Returns the value of attribute fields.



7
8
9
# File 'lib/sso/elements/config.rb', line 7

def fields
  @fields
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/sso/elements/config.rb', line 7

def name
  @name
end

#offsetObject

Returns the value of attribute offset.



7
8
9
# File 'lib/sso/elements/config.rb', line 7

def offset
  @offset
end

#typeObject

Returns the value of attribute type.



7
8
9
# File 'lib/sso/elements/config.rb', line 7

def type
  @type
end

#typesObject

Returns the value of attribute types.



7
8
9
# File 'lib/sso/elements/config.rb', line 7

def types
  @types
end

#valuesObject

Returns the value of attribute values.



7
8
9
# File 'lib/sso/elements/config.rb', line 7

def values
  @values
end

Instance Method Details

#add_element(element) ⇒ Object



53
54
55
56
57
58
# File 'lib/sso/elements/config.rb', line 53

def add_element(element)
  @values << element.to_value
  @elements << element

  true
end

#elementsObject



41
42
43
44
45
46
47
# File 'lib/sso/elements/config.rb', line 41

def elements
  return @elements if @elements

  @elements = values.map do |value|
    Element.from_value(self, value)
  end
end

#elements_loaded?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/sso/elements/config.rb', line 49

def elements_loaded?
  !@elements.nil?
end

#find_element_by_id(id) ⇒ Object



60
61
62
63
64
# File 'lib/sso/elements/config.rb', line 60

def find_element_by_id(id)
  elements.find do |element|
    element.id == id
  end
end

#find_element_by_name(name) ⇒ Object



66
67
68
69
70
# File 'lib/sso/elements/config.rb', line 66

def find_element_by_name(name)
  elements.find do |element|
    element.name.to_s.downcase == name.to_s.downcase
  end
end

#find_elements_by_name(name) ⇒ Object



72
73
74
75
76
# File 'lib/sso/elements/config.rb', line 72

def find_elements_by_name(name)
  elements.select do |element|
    element.name.to_s.downcase.include?(name.to_s.downcase)
  end
end

#grouped_field_quantityObject



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/sso/elements/config.rb', line 77

def grouped_field_quantity
  return @fields_quantity if @fields_quantity

  @fields_quantity = {}

  fields.each do |field|
    @fields_quantity[field] ||= 0
    @fields_quantity[field]  += 1
  end

  @fields_quantity
end

#to_jsonObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sso/elements/config.rb', line 26

def to_json
  values.map do |value|
    result = {}

    value.each_with_index do |data, index|
      result[fields[index]] = {
        'data' => data,
        'type' => types[index]
      }
    end

    result
  end
end