Class: Moonrope::StructureAttribute

Inherits:
Object
  • Object
show all
Defined in:
lib/moonrope/structure_attribute.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, name) ⇒ StructureAttribute

Returns a new instance of StructureAttribute.



17
18
19
20
21
22
# File 'lib/moonrope/structure_attribute.rb', line 17

def initialize(type, name)
  @type = type
  @name = name
  @groups = []
  @conditions = []
end

Instance Attribute Details

#conditionsObject

Returns the value of attribute conditions.



6
7
8
# File 'lib/moonrope/structure_attribute.rb', line 6

def conditions
  @conditions
end

#descriptionObject

Returns the value of attribute description.



8
9
10
# File 'lib/moonrope/structure_attribute.rb', line 8

def description
  @description
end

#docObject

Returns the value of attribute doc.



14
15
16
# File 'lib/moonrope/structure_attribute.rb', line 14

def doc
  @doc
end

#exampleObject

Returns the value of attribute example.



13
14
15
# File 'lib/moonrope/structure_attribute.rb', line 13

def example
  @example
end

#groupsObject

Returns the value of attribute groups.



5
6
7
# File 'lib/moonrope/structure_attribute.rb', line 5

def groups
  @groups
end

#mutationObject

Returns the value of attribute mutation.



15
16
17
# File 'lib/moonrope/structure_attribute.rb', line 15

def mutation
  @mutation
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/moonrope/structure_attribute.rb', line 4

def name
  @name
end

#source_attributeObject

Returns the value of attribute source_attribute.



7
8
9
# File 'lib/moonrope/structure_attribute.rb', line 7

def source_attribute
  @source_attribute
end

#structureObject

Returns the value of attribute structure.



10
11
12
# File 'lib/moonrope/structure_attribute.rb', line 10

def structure
  @structure
end

#structure_optsObject

Returns the value of attribute structure_opts.



11
12
13
# File 'lib/moonrope/structure_attribute.rb', line 11

def structure_opts
  @structure_opts
end

#valueObject

Returns the value of attribute value.



12
13
14
# File 'lib/moonrope/structure_attribute.rb', line 12

def value
  @value
end

#value_typeObject

Returns the value of attribute value_type.



9
10
11
# File 'lib/moonrope/structure_attribute.rb', line 9

def value_type
  @value_type
end

Instance Method Details

#auto_mutate(value) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/moonrope/structure_attribute.rb', line 40

def auto_mutate(value)
  case value_type
  when :timestamp
    value.is_a?(Time) ? value.to_s : value
  when :unix_timestamp
    value.nil? ? nil : value.to_i
  else
    value
  end
end

#mutate(value) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/moonrope/structure_attribute.rb', line 32

def mutate(value)
  if mutation
    value ? value.public_send(mutation) : nil
  else
    auto_mutate(value)
  end
end

#name_with_groupsObject



28
29
30
# File 'lib/moonrope/structure_attribute.rb', line 28

def name_with_groups
  ([groups] + [name]).flatten.compact.join('.')
end