Class: Labimotion::PropertiesHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/labimotion/libs/properties_handler.rb

Class Method Summary collapse

Class Method Details

.check_properties(properties) ⇒ Object



50
51
52
# File 'lib/labimotion/libs/properties_handler.rb', line 50

def self.check_properties(properties)
  properties.nil? || !properties.is_a?(Hash) || properties[Labimotion::Prop::LAYERS].nil? || properties[Labimotion::Prop::LAYERS].keys.empty?
end

.copy(properties, key, type) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/labimotion/libs/properties_handler.rb', line 81

def self.copy(properties, key, type)
  fields = properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS].select { |ss| ss['type'] == type }
  fields.each do |field|
    next unless check_val(field, type)

    idx = properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS].index(field)
    ## TODO Copy Sample...
  end
  properties
rescue StandardError => e
  Labimotion.log_exception(e)
  properties
end

.delete_field_key!(properties, layer_key, field_index, key) ⇒ Object

Delete field key



101
102
103
# File 'lib/labimotion/libs/properties_handler.rb', line 101

def self.delete_field_key!(properties, layer_key, field_index, key)
  properties[Labimotion::Prop::LAYERS][layer_key][Labimotion::Prop::FIELDS][field_index].delete(key)
end

.detach(properties, key, type) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/labimotion/libs/properties_handler.rb', line 54

def self.detach(properties, key, type)
  fields = properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS].select { |ss| ss['type'] == type }
  fields.each do |field|
    next unless check_val(field, type)

    properties = detach_val(properties, field, key, type)
  end
  properties
rescue StandardError => e
  Labimotion.log_exception(e)
  properties
end

.split(properties, key, type) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/labimotion/libs/properties_handler.rb', line 67

def self.split(properties, key, type)
  fields = properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS].select { |ss| ss['type'] == type }
  fields.each do |field|
    next unless check_val(field, type)

    idx = properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS].index(field)
    ## TODO Split ...
  end
  properties
rescue StandardError => e
  Labimotion.log_exception(e)
  properties
end

.update_field_value!(properties, layer_key, field_index, value) ⇒ Object

Update field with value



96
97
98
# File 'lib/labimotion/libs/properties_handler.rb', line 96

def self.update_field_value!(properties, layer_key, field_index, value)
  properties[Labimotion::Prop::LAYERS][layer_key][Labimotion::Prop::FIELDS][field_index]['value'] = value
end