Class: FFXIVLodestone::Character::SkillList

Inherits:
Hash
  • Object
show all
Defined in:
lib/ffxiv-lodestone.rb

Overview

StatList

Defined Under Namespace

Classes: Skill

Instance Method Summary collapse

Constructor Details

#initialize(skill_table) ⇒ SkillList

Skill



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/ffxiv-lodestone.rb', line 118

def initialize(skill_table)
  @skills = {}

  skill_table.children.each do |skill|
    name = skill.children[0].content
    if FFXIVLodestone::SKILL_TO_CLASS.key? name
      key = FFXIVLodestone::SKILL_TO_CLASS[name]
      job = key.to_s.capitalize
    else
      key = name.gsub('-', '_').downcase.to_sym
      job = name
    end

    # '-' = not leveled (never equipped the class' weapon)
    rank = skill.children[1].search('table tr td[last()]').children.first.content
    rank = (rank.include?('-') ? 0 : rank.to_i)

    # # '-' = not leveled, otherwise it will be in the format '391 / 1500'
    sp = skill.children[2].search('table tr td[last()]').children.first.content

    if sp.include? '-'
      current_sp = 0
      levelup_sp = 0
    else
      sp.strip_nbsp!
      current_sp = sp.split('/')[0].strip.to_i
      levelup_sp = sp.split('/')[1].strip.to_i
    end

    self[key] = Skill.new(job,name,rank,current_sp,levelup_sp)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object



159
160
161
162
# File 'lib/ffxiv-lodestone.rb', line 159

def method_missing(method)
  return self[method] if self.key? method
  super
end

Instance Method Details

#levelledObject

Lists all leveled (rank > 0) jobs.



152
153
154
155
156
157
# File 'lib/ffxiv-lodestone.rb', line 152

def levelled 
  self.keys.reduce(Array.new) do |a,key| 
    a << self.send(key) if self.send(key).rank > 0
    a
  end
end