Class: PfrpgUtility::Prerequisite

Inherits:
Object
  • Object
show all
Defined in:
lib/pfrpg_utility/prerequisite.rb

Defined Under Namespace

Classes: AlignmentPrereq, AttributePrereq, BabPrereq, ClassPrereq, FeatPrereq, HeroclassFeaturePrereq, LanguagePrereq, MiscPrereq, SkillPrereq

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute, value, matcher = nil) ⇒ Prerequisite

Returns a new instance of Prerequisite.



4
5
6
7
8
9
10
11
# File 'lib/pfrpg_utility/prerequisite.rb', line 4

def initialize(attribute, value, matcher=nil)
  default_matcher = Proc.new do |character, attribute, value|
    true
  end
  @attribute = attribute
  @value     = value
  @matcher   = matcher || default_matcher
end

Class Method Details

.load(prereq_string) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/pfrpg_utility/prerequisite.rb', line 13

def self.load(prereq_string)
  begin
    prereqs = []
    p = prereq_string.split(";")
    p.each { |x| prereqs << parse_prereq(x) }
    prereqs
  rescue Exception
    []
  end
end

.parse_prereq(string) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/pfrpg_utility/prerequisite.rb', line 24

def self.parse_prereq(string)
  p = string.split(":")
  type = p[0]
  attribute = p[1]
  value = p[2]
  case type
  when "class"
    Prerequisite::ClassPrereq.new(attribute, value)
  when "attribute"
    Prerequisite::AttributePrereq.new(attribute, value)
  when "alignment"
    Prerequisite::AlignmentPrereq.new(attribute, value)
  when "feat"
    Prerequisite::FeatPrereq.new(attribute, value)
  when "skill"
    Prerequisite::SkillPrereq.new(attribute, value)
  when "class_feature"
    Prerequisite::HeroclassFeaturePrereq.new(attribute, value)
  when "combat"
    Prerequisite::BabPrereq.new(attribute, value)
  when "language"
    Prerequisite::LanguagePrereq.new(attribute, value)
  when "misc"
    Prerequisite::MiscPrereq.new(attribute, value)
  else
    Prerequisite.new(attribute, value)
  end
end

Instance Method Details

#match(character) ⇒ Object



53
54
55
# File 'lib/pfrpg_utility/prerequisite.rb', line 53

def match(character)
  @matcher.call(character, @attribute, @value)
end