Class: Interscript::Node::Item::Alias

Inherits:
Interscript::Node::Item show all
Defined in:
lib/interscript/node/item/alias.rb,
lib/interscript/visualize/nodes.rb

Instance Attribute Summary collapse

Attributes inherited from Interscript::Node::Item

#item

Instance Method Summary collapse

Methods inherited from Interscript::Node::Item

#+, try_convert

Constructor Details

#initialize(name, map: nil) ⇒ Alias

Returns a new instance of Alias.



4
5
6
7
# File 'lib/interscript/node/item/alias.rb', line 4

def initialize(name, map: nil)
  self.name = name
  self.map = map
end

Instance Attribute Details

#mapObject

Returns the value of attribute map.



3
4
5
# File 'lib/interscript/node/item/alias.rb', line 3

def map
  @map
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/interscript/node/item/alias.rb', line 2

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object



43
44
45
# File 'lib/interscript/node/item/alias.rb', line 43

def ==(other)
  super && self.name == other.name && self.map == other.map
end

#boundary_like?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/interscript/node/item/alias.rb', line 13

def boundary_like?
  Interscript::Stdlib.boundary_like_alias?(name)
end

#downcaseObject

Not implemented properly



27
# File 'lib/interscript/node/item/alias.rb', line 27

def downcase; self; end

#first_stringObject Also known as: nth_string



30
31
32
# File 'lib/interscript/node/item/alias.rb', line 30

def first_string
  self
end

#inspectObject



47
48
49
50
51
52
53
# File 'lib/interscript/node/item/alias.rb', line 47

def inspect
  if map
    "map.#{map}.#{name}"
  else
    "#{name}"
  end
end

#max_lengthObject



17
18
19
20
21
22
23
24
# File 'lib/interscript/node/item/alias.rb', line 17

def max_length
  if stdlib?
    ([:none].include? name) ? 0 : 1
  else
    return 1 if name == :unicode_hangul
    raise NotImplementedError, "can't get a max length of this alias"
  end
end

#stdlib?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/interscript/node/item/alias.rb', line 9

def stdlib?
  !map && Interscript::Stdlib::ALIASES.has_key?(name)
end

#to_hashObject



36
37
38
39
40
41
# File 'lib/interscript/node/item/alias.rb', line 36

def to_hash
  { :class => self.class.to_s,
    :name => name,
    :map => map,
  }
end

#to_html(doc) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/interscript/visualize/nodes.rb', line 3

def to_html(doc)
  if map
    n = doc.dep_aliases[map].full_name
    "#{name.to_s.gsub("_", " ")} from map #{n}"
  else
    "#{name.to_s.gsub("_", " ")}"
  end
end

#upcaseObject



28
# File 'lib/interscript/node/item/alias.rb', line 28

def upcase; self; end