Class: CML::Gold
- Inherits:
-
Object
- Object
- CML::Gold
- Defined in:
- lib/cml/gold.rb
Constant Summary collapse
- Attrs =
["exact","strict","regex","structured","matcher","superset"]
- ATTR_ALIASES =
{'subset' => 'strict'}
Instance Method Summary collapse
-
#initialize(tag, gold) ⇒ Gold
constructor
A new instance of Gold.
- #to_hash ⇒ Object
Constructor Details
#initialize(tag, gold) ⇒ Gold
Returns a new instance of Gold.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/cml/gold.rb', line 7 def initialize(tag, gold) @tag = tag @name = @tag.name(false) @src = (gold.attributes["gold"] || gold.attributes["src"]).to_s @src = "#{@name}_gold" if @src =~ /^(true|\s*)$/ (Attrs + ATTR_ALIASES.keys).each do |attribute| if a = gold.attributes[attribute] attribute = ATTR_ALIASES[attribute] || attribute value = case attribute when "regex" [a.to_s, gold.attributes["flags"].to_s, gold.attributes["no_escape"].to_s] when "matcher" a.to_s else a.to_s == "true" end instance_variable_set "@#{attribute}", value end end @structured = true if @tag. end |
Instance Method Details
#to_hash ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/cml/gold.rb', line 29 def to_hash Hash[ *[@name,@src].concat(Attrs.map do |a| val = instance_variable_get("@#{a}") val ? ["_#{@src}_#{a}", val] : nil end.compact.flatten(1)) ] end |