Class: Rubiks::Level

Inherits:
NamedObject show all
Defined in:
lib/rubiks/level.rb

Instance Method Summary collapse

Methods inherited from NamedObject

[], #caption, clear!, default, #default_json_attributes, #default_xml_attributes, define, #description, find_or_create, #hidden, #icon_type, #initialize, instances, #name, #table, #table_with_prefix, #to_json

Constructor Details

This class inherits a constructor from Rubiks::NamedObject

Instance Method Details

#cardinality(new_value = nil) ⇒ Object



4
5
6
7
# File 'lib/rubiks/level.rb', line 4

def cardinality(new_value=nil)
  @cardinality = new_value.to_s if new_value.present?
  @cardinality ||= @options[:cardinality]
end

#column(new_value = nil) ⇒ Object



14
15
16
17
# File 'lib/rubiks/level.rb', line 14

def column(new_value=nil)
  @column = new_value.to_s if new_value.present?
  @column ||= @options[:column] || name
end

#contiguous(new_value = nil) ⇒ Object



9
10
11
12
# File 'lib/rubiks/level.rb', line 9

def contiguous(new_value=nil)
  @contiguous = new_value.to_s if new_value.present?
  @contiguous ||= @options.key?(:contiguous) ? @options[:contiguous].to_s : nil
end

#json_hashObject



39
40
41
42
43
44
45
# File 'lib/rubiks/level.rb', line 39

def json_hash
  hash = default_json_attributes
  hash[:cardinality] = cardinality.to_s if cardinality.present?
  hash[:hidden] = hidden if hidden.present? && hidden == 'false'
  hash[:contiguous] = contiguous if contiguous.present? && contiguous == 'true'
  hash.stringify_keys!
end

#level_type(new_value = nil) ⇒ Object



29
30
31
32
# File 'lib/rubiks/level.rb', line 29

def level_type(new_value=nil)
  @level_type = new_value.to_s if new_value.present?
  @level_type ||= @options[:level_type]
end

#name_column(new_value = nil) ⇒ Object



19
20
21
22
# File 'lib/rubiks/level.rb', line 19

def name_column(new_value=nil)
  @name_column = new_value.to_s if new_value.present?
  @name_column ||= @options[:name_column]
end

#ordinal_column(new_value = nil) ⇒ Object



24
25
26
27
# File 'lib/rubiks/level.rb', line 24

def ordinal_column(new_value=nil)
  @ordinal_column = new_value.to_s if new_value.present?
  @ordinal_column ||= @options[:ordinal_column]
end

#to_xml(builder = nil) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/rubiks/level.rb', line 47

def to_xml(builder = nil)
  builder = builder || new_builder

  xml_attrs = default_xml_attributes.merge(:column => column)
  xml_attrs[:nameColumn] = name_column if name_column.present?
  xml_attrs[:ordinalColumn] = ordinal_column if ordinal_column.present?
  xml_attrs[:levelType] = level_type if level_type.present?
  xml_attrs[:type] = type.to_s.capitalize if type.present?
  builder.level(xml_attrs)
end

#type(new_value = nil) ⇒ Object



34
35
36
37
# File 'lib/rubiks/level.rb', line 34

def type(new_value=nil)
  @type = new_value if new_value.present?
  @type ||= @options[:type]
end