Class: Glaemscribe::API::Charset::Swap

Inherits:
Object
  • Object
show all
Defined in:
lib/api/charset.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(trigger, target_list) ⇒ Swap

Returns a new instance of Swap.



38
39
40
41
42
43
# File 'lib/api/charset.rb', line 38

def initialize(trigger, target_list)
  @trigger = trigger
  @targets = {}

  @target_list = target_list
end

Instance Attribute Details

#lineObject

Returns the value of attribute line.



34
35
36
# File 'lib/api/charset.rb', line 34

def line
  @line
end

#targetsObject

Returns the value of attribute targets.



36
37
38
# File 'lib/api/charset.rb', line 36

def targets
  @targets
end

#triggerObject

Returns the value of attribute trigger.



35
36
37
# File 'lib/api/charset.rb', line 35

def trigger
  @trigger
end

Instance Method Details

#finalize(charset) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/api/charset.rb', line 45

def finalize(charset)
  @lookup_table = {}

  trig = charset.n2c(@trigger)

  if !trig
    charset.errors << Glaeml::Error.new(@line, "Swap operator triggers #{@trigger} which does not exist in charset.")
  end

  @target_list.each{ |target_id|
    c = charset.n2c(target_id)
    if !c
       charset.errors << Glaeml::Error.new(@line, "Swap operator targets #{target_id} which does not exist in charset.")
    else
      c.names.each{ |n|
        @targets[n]  = c
      }
    end
  }

  trig
end

#has_target?(tname) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/api/charset.rb', line 68

def has_target?(tname)
  (@targets[tname] != nil)
end