Class: PfrpgImport::Level

Inherits:
Object
  • Object
show all
Includes:
CaseHelpers
Defined in:
lib/pfrpg_import/level.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CaseHelpers

#arrayify, #camelized_title, #underscored_title

Constructor Details

#initialize(params) ⇒ Level

Returns a new instance of Level.



6
7
8
9
10
11
12
13
14
# File 'lib/pfrpg_import/level.rb', line 6

def initialize(params)
  @level = parse_level(params[:level])
  @bab = parse_bab(params[:bab])
  @fort_save = parse_save(params[:fort_save])
  @ref_save = parse_save(params[:ref_save])
  @will_save = parse_save(params[:will_save])
  @granted_features = parse_features(params[:granted_features])
  @choices = parse_choices(params[:choices])
end

Instance Attribute Details

#babObject (readonly)

Returns the value of attribute bab.



4
5
6
# File 'lib/pfrpg_import/level.rb', line 4

def bab
  @bab
end

#choicesObject (readonly)

Returns the value of attribute choices.



4
5
6
# File 'lib/pfrpg_import/level.rb', line 4

def choices
  @choices
end

#fort_saveObject (readonly)

Returns the value of attribute fort_save.



4
5
6
# File 'lib/pfrpg_import/level.rb', line 4

def fort_save
  @fort_save
end

#granted_featuresObject (readonly)

Returns the value of attribute granted_features.



4
5
6
# File 'lib/pfrpg_import/level.rb', line 4

def granted_features
  @granted_features
end

#levelObject (readonly)

Returns the value of attribute level.



4
5
6
# File 'lib/pfrpg_import/level.rb', line 4

def level
  @level
end

#ref_saveObject (readonly)

Returns the value of attribute ref_save.



4
5
6
# File 'lib/pfrpg_import/level.rb', line 4

def ref_save
  @ref_save
end

#will_saveObject (readonly)

Returns the value of attribute will_save.



4
5
6
# File 'lib/pfrpg_import/level.rb', line 4

def will_save
  @will_save
end

Instance Method Details

#parse_bab(bab_string) ⇒ Object



20
21
22
# File 'lib/pfrpg_import/level.rb', line 20

def parse_bab(bab_string)
  return arrayify(bab_string.gsub("+", "").split('/'))
end

#parse_choices(choices) ⇒ Object



33
34
35
36
# File 'lib/pfrpg_import/level.rb', line 33

def parse_choices(choices)
  return 'nil' if (!choices || choices.empty?)
  return arrayify(choices)
end

#parse_features(features) ⇒ Object



28
29
30
31
# File 'lib/pfrpg_import/level.rb', line 28

def parse_features(features)
  return 'nil' if (!features || features.empty?)
  return arrayify(features.split(',').map { |x| "\'#{x.underscore.downcase}\'" })
end

#parse_level(level) ⇒ Object



16
17
18
# File 'lib/pfrpg_import/level.rb', line 16

def parse_level(level)
  return Integer(level.gsub("nd","").gsub("th","").gsub("st","").gsub("rd",""))
end

#parse_save(save) ⇒ Object



24
25
26
# File 'lib/pfrpg_import/level.rb', line 24

def parse_save(save)
  return save.gsub("+", "")
end

#to_s(title) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/pfrpg_import/level.rb', line 38

def to_s(title)
  <<-eos
  when #{level}
bonus = { :base_attack_bonus => #{bab},
          :fort_save         => #{fort_save},
          :ref_save          => #{ref_save},
          :will_save         => #{will_save},
          :granted_features  => #{granted_features},
          :choices           => #{choices},
          :spells_per_day => Tables::Spells::SpellsPerDay.#{title}(#{level})
        }
  eos
end