lib/oxmlk/attr.rb in oxmlk-0.3.3 vs lib/oxmlk/attr.rb in oxmlk-0.4.0
- old
+ new
@@ -1,9 +1,9 @@
module OxMlk
class Attr
- attr_reader :accessor, :setter,:from, :as, :procs, :tag_proc, :tag
+ attr_reader :accessor, :setter, :from, :as, :procs, :tag_proc, :tag
# Named Procs for use in :as option.
PROCS = (Hash.new {|h,k| k.to_proc rescue nil}).merge(
Integer => :to_i.to_proc,
Float => :to_f.to_proc,
@@ -42,15 +42,15 @@
@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
- private
-
# Finds @tag in data and applies procs.
def from_xml(data)
procs.inject(XML::Node.from(data)[tag]) {|d,p| p.call(d) rescue d}
end
+
+ private
# Converts a value to a Boolean.
# @param [Symbol,String,Integer] value Value to convert
# @return [Boolean] Returns true if value is 'true', 'yes', 't' or 1.
# Returns false if value is 'false', 'no', 'f' or 0.
\ No newline at end of file