Class: Parameter
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Parameter
- Includes:
- Validation
- Defined in:
- lib/generators/rcap/models/templates/models/parameter.rb
Overview
A Parameter object is valid if
-
it has a name
-
it has a value
Direct Known Subclasses
Constant Summary collapse
- XML_ELEMENT_NAME =
:nodoc:
"parameter"
- NAME_ELEMENT_NAME =
:nodoc:
"valueName"
- VALUE_ELEMENT_NAME =
:nodoc:
"value"
- XPATH =
:nodoc:
"cap:#{ XML_ELEMENT_NAME }"
- NAME_XPATH =
:nodoc:
"cap:#{ NAME_ELEMENT_NAME }"
- VALUE_XPATH =
:nodoc:
"cap:#{ VALUE_ELEMENT_NAME }"
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
-
.from_h(hash) ⇒ Object
:nodoc:.
-
.from_xml_element(parameter_xml_element) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Two parameters are equivalent if they have the same name and value.
-
#initialize(attributes = {}) ⇒ Parameter
constructor
A new instance of Parameter.
-
#inspect ⇒ Object
:nodoc:.
-
#to_h ⇒ Object
:nodoc:.
-
#to_s ⇒ Object
Returns a string representation of the parameter of the form name: value.
-
#to_xml ⇒ Object
:nodoc:.
-
#to_xml_element ⇒ Object
:nodoc:.
Constructor Details
#initialize(attributes = {}) ⇒ Parameter
Returns a new instance of Parameter.
19 20 21 22 |
# File 'lib/generators/rcap/models/templates/models/parameter.rb', line 19 def initialize( attributes = {} ) @name = attributes[ :name ] @value = attributes[ :value ] end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/generators/rcap/models/templates/models/parameter.rb', line 9 def name @name end |
#value ⇒ Object
Returns the value of attribute value.
9 10 11 |
# File 'lib/generators/rcap/models/templates/models/parameter.rb', line 9 def value @value end |
Class Method Details
.from_h(hash) ⇒ Object
:nodoc:
60 61 62 63 |
# File 'lib/generators/rcap/models/templates/models/parameter.rb', line 60 def self.from_h( hash ) # :nodoc: key = hash.keys.first self.new( :name => key, :value => hash[ key ]) end |
.from_xml_element(parameter_xml_element) ⇒ Object
:nodoc:
45 46 47 48 |
# File 'lib/generators/rcap/models/templates/models/parameter.rb', line 45 def self.from_xml_element( parameter_xml_element ) # :nodoc: Parameter.new( :name => RCAP.xpath_text( parameter_xml_element, NAME_XPATH ), :value => RCAP.xpath_text( parameter_xml_element, VALUE_XPATH )) end |
Instance Method Details
#==(other) ⇒ Object
Two parameters are equivalent if they have the same name and value.
51 52 53 |
# File 'lib/generators/rcap/models/templates/models/parameter.rb', line 51 def ==( other ) [ self.name, self.value ] == [ other.name, other.value ] end |
#inspect ⇒ Object
:nodoc:
35 36 37 |
# File 'lib/generators/rcap/models/templates/models/parameter.rb', line 35 def inspect # :nodoc: "#{ self.name }: #{ self.value }" end |
#to_h ⇒ Object
:nodoc:
55 56 57 58 |
# File 'lib/generators/rcap/models/templates/models/parameter.rb', line 55 def to_h # :nodoc: RCAP.attribute_values_to_hash( [ @name, @value ]) end |
#to_s ⇒ Object
Returns a string representation of the parameter of the form
name: value
41 42 43 |
# File 'lib/generators/rcap/models/templates/models/parameter.rb', line 41 def to_s self.inspect end |
#to_xml ⇒ Object
:nodoc:
31 32 33 |
# File 'lib/generators/rcap/models/templates/models/parameter.rb', line 31 def to_xml # :nodoc: self.to_xml_element.to_s end |
#to_xml_element ⇒ Object
:nodoc:
24 25 26 27 28 29 |
# File 'lib/generators/rcap/models/templates/models/parameter.rb', line 24 def to_xml_element # :nodoc: xml_element = REXML::Element.new( XML_ELEMENT_NAME ) xml_element.add_element( NAME_ELEMENT_NAME ).add_text( self.name ) xml_element.add_element( VALUE_ELEMENT_NAME ).add_text( self.value ) xml_element end |