Class: Ebay::Schema::Node

Inherits:
Object
  • Object
show all
Includes:
Inflections
Defined in:
lib/ebay/schema/mapper/node.rb

Constant Summary

Constants included from Inflections

Inflections::DOWNCASE_TOKENS, Inflections::NAME_MAPPINGS, Inflections::UPCASE_TOKENS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Inflections

#downcase_first_character, #ebay_camelize, #ebay_underscore, #underscore, #upcase_first_character

Constructor Details

#initialize(name, attributes = {}) ⇒ Node

Returns a new instance of Node.



8
9
10
11
12
13
14
15
# File 'lib/ebay/schema/mapper/node.rb', line 8

def initialize(name, attributes = {})
  @name = name
  @type = attributes[:type]
  @min = attributes[:min] || "1"
  @max = attributes[:max] || "1"
  @field = attributes[:field]
  @child = attributes[:child]
end

Instance Attribute Details

#maxObject

Returns the value of attribute max.



7
8
9
# File 'lib/ebay/schema/mapper/node.rb', line 7

def max
  @max
end

#minObject

Returns the value of attribute min.



7
8
9
# File 'lib/ebay/schema/mapper/node.rb', line 7

def min
  @min
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/ebay/schema/mapper/node.rb', line 7

def name
  @name
end

Instance Method Details

#accessor_nameObject



21
22
23
24
25
26
27
28
29
# File 'lib/ebay/schema/mapper/node.rb', line 21

def accessor_name
  name = ebay_underscore(@name)
  if name =~ /_array$/
    name.gsub!(/_array$/, '')
    Inflector.pluralize(name)
  else
    name
  end
end

#declarationObject



35
36
37
# File 'lib/ebay/schema/mapper/node.rb', line 35

def declaration
  "#{xml_mapping_node_type} :#{accessor_name}"
end

#optional?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/ebay/schema/mapper/node.rb', line 17

def optional?
  @min == "0"
end

#xml_mapping_node_typeObject



31
32
33
# File 'lib/ebay/schema/mapper/node.rb', line 31

def xml_mapping_node_type
  override_type || Inflector.demodulize(self.class.to_s).underscore
end