Class: Interscript::Node::Item::Any
- Inherits:
-
Interscript::Node::Item
- Object
- Interscript::Node
- Interscript::Node::Item
- Interscript::Node::Item::Any
- Defined in:
- lib/interscript/node/item/any.rb,
lib/interscript/visualize/nodes.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Attributes inherited from Interscript::Node::Item
Instance Method Summary collapse
- #==(other) ⇒ Object
- #data ⇒ Object
- #downcase ⇒ Object
- #first_string ⇒ Object
-
#initialize(data) ⇒ Any
constructor
A new instance of Any.
- #inspect ⇒ Object
- #max_length ⇒ Object
- #nth_string ⇒ Object
- #to_hash ⇒ Object
- #to_html(doc) ⇒ Object
- #upcase ⇒ Object
Methods inherited from Interscript::Node::Item
Constructor Details
#initialize(data) ⇒ Any
Returns a new instance of Any.
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/interscript/node/item/any.rb', line 3 def initialize data case data when Array, ::String, Range self.value = data when Interscript::Node::Item::Group # debug alalc-ara-Arab-Latn-1997 line 683 self.value = data.children when Interscript::Node::Item::Alias # debug mofa-jpn-Hrkt-Latn-1989 line 116 self.value = Interscript::Stdlib::ALIASES[data.name] else puts data.inspect raise Interscript::MapLogicError, "Wrong type #{data[0].class}, excepted Array, String or Range" end end |
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
2 3 4 |
# File 'lib/interscript/node/item/any.rb', line 2 def value @value end |
Instance Method Details
#==(other) ⇒ Object
76 77 78 |
# File 'lib/interscript/node/item/any.rb', line 76 def ==(other) super && self.data == other.data end |
#data ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/interscript/node/item/any.rb', line 17 def data case @value when Array value.map { |i| Interscript::Node::Item.try_convert(i) } when ::String value.split("").map { |i| Interscript::Node::Item.try_convert(i) } when Range value.map { |i| Interscript::Node::Item.try_convert(i) } end end |
#downcase ⇒ Object
28 |
# File 'lib/interscript/node/item/any.rb', line 28 def downcase; self.class.new(self.data.map(&:downcase)); end |
#first_string ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/interscript/node/item/any.rb', line 31 def first_string case @value when Array Interscript::Node::Item.try_convert(value.first).first_string when ::String value[0] when Range value.begin end end |
#inspect ⇒ Object
80 81 82 |
# File 'lib/interscript/node/item/any.rb', line 80 def inspect "any(#{value.inspect})" end |
#max_length ⇒ Object
52 53 54 |
# File 'lib/interscript/node/item/any.rb', line 52 def max_length self.data.map(&:max_length).max end |
#nth_string ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/interscript/node/item/any.rb', line 42 def nth_string return first_string unless $select_nth_string d = data Fiber.yield(:prepare) id = Fiber.yield(:select_nth_string, d.count, self.hash) Fiber.yield(:selection) Interscript::Node::Item.try_convert(value[id]).nth_string end |
#to_hash ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/interscript/node/item/any.rb', line 56 def to_hash hash = { :class => self.class.to_s } case @value when Array hash[:type] = "Array" hash[:data] = data.map { |i| i.to_hash } when ::String hash[:type] = "String" hash[:data] = @value when Range hash[:type] = "Range" hash[:data] = [@value.begin, @value.end] when NilClass hash[:type] = "nil (bug)" end hash end |
#to_html(doc) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/interscript/visualize/nodes.rb', line 25 def to_html(doc) "<nobr>any (</nobr>" + case @value when Array value.map(&Interscript::Node::Item.method(:try_convert)).map{|i|i.to_html(doc)}.join(", ") when ::String value.split("").map(&Interscript::Node::Item.method(:try_convert)).map{|i|i.to_html(doc)}.join(", ") when Range [value.begin, value.end].map(&Interscript::Node::Item.method(:try_convert)).map{|i|i.to_html(doc)}.join(" to ") else h(value.inspect) end + ")" end |
#upcase ⇒ Object
29 |
# File 'lib/interscript/node/item/any.rb', line 29 def upcase; self.class.new(self.data.map(&:upcase)); end |