Class: OxMlk::Attr
- Inherits:
-
Object
- Object
- OxMlk::Attr
- Defined in:
- lib/oxmlk/attr.rb
Constant Summary collapse
- PROCS =
Named Procs for use in :as option.
(Hash.new {|h,k| k.to_proc rescue nil}).merge( Integer => :to_i.to_proc, Float => :to_f.to_proc, String => :to_s.to_proc, Symbol => :to_sym.to_proc, :bool => proc {|a| fetch_bool(a)})
Instance Attribute Summary collapse
-
#accessor ⇒ Object
readonly
Returns the value of attribute accessor.
-
#as ⇒ Object
readonly
Returns the value of attribute as.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#procs ⇒ Object
readonly
Returns the value of attribute procs.
-
#setter ⇒ Object
readonly
Returns the value of attribute setter.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
-
#tag_proc ⇒ Object
readonly
Returns the value of attribute tag_proc.
Instance Method Summary collapse
-
#from_xml(data) ⇒ Object
Finds @tag in data and applies procs.
-
#initialize(name, o = {}) {|String| ... } ⇒ Attr
constructor
Creates a new instance of Attr to be used as a template for converting XML to objects and from objects to XML.
Constructor Details
#initialize(name, o = {}) {|String| ... } ⇒ Attr
Creates a new instance of Attr to be used as a template for converting XML to objects and from objects to XML
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/oxmlk/attr.rb', line 36 def initialize(name,o={},&block) name = name.to_s @accessor = name.chomp('?').intern @setter = "#{@accessor}=".intern @from = o[:from] @tag_proc = o[:tag_proc].to_proc rescue proc {|x| x} @tag = (from || (@tag_proc.call(accessor.to_s) rescue accessor)).to_s @as = o[:as] || (:bool if name.ends_with?('?')) @procs = ([*as].map {|k| PROCS[k]} + [block]).compact end |
Instance Attribute Details
#accessor ⇒ Object (readonly)
Returns the value of attribute accessor.
4 5 6 |
# File 'lib/oxmlk/attr.rb', line 4 def accessor @accessor end |
#as ⇒ Object (readonly)
Returns the value of attribute as.
4 5 6 |
# File 'lib/oxmlk/attr.rb', line 4 def as @as end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
4 5 6 |
# File 'lib/oxmlk/attr.rb', line 4 def from @from end |
#procs ⇒ Object (readonly)
Returns the value of attribute procs.
4 5 6 |
# File 'lib/oxmlk/attr.rb', line 4 def procs @procs end |
#setter ⇒ Object (readonly)
Returns the value of attribute setter.
4 5 6 |
# File 'lib/oxmlk/attr.rb', line 4 def setter @setter end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
4 5 6 |
# File 'lib/oxmlk/attr.rb', line 4 def tag @tag end |
#tag_proc ⇒ Object (readonly)
Returns the value of attribute tag_proc.
4 5 6 |
# File 'lib/oxmlk/attr.rb', line 4 def tag_proc @tag_proc end |