Class: Archivist
- Inherits:
-
Object
- Object
- Archivist
- Defined in:
- lib/Archivist.rb
Constant Summary collapse
- @@source =
"https://2e.aonprd.com/"
- @@ance_parser =
/Ability Boosts(Str.+|Dex.+|Con.+|Int.+|Wis.+|Cha.+)(Str.+|Dex.+|Con.+|Int.+|Wis.+|Cha.+)FreeAbility Flaw\(s\)(Str.+|Dex.+|Con.+|Int.+|Wis.+|Cha.+)Languages/
- @@back_parser =
/be to (Str.+|Dex.+|Con.+|Int.+|Wis.+|Cha.+) or (Str.+|Dex.+|Con.+|Int.+|Wis.+|Cha.+), and one/
- @@clas_parser =
/(STR\w+|DEX\w+|CON\w+|INT\w+|WIS\w+|CHA\w+)/
Instance Attribute Summary collapse
-
#ancestries ⇒ Object
readonly
Returns the value of attribute ancestries.
-
#backgrounds ⇒ Object
readonly
Returns the value of attribute backgrounds.
-
#classes ⇒ Object
readonly
Returns the value of attribute classes.
Instance Method Summary collapse
-
#ance_stats(option, aspect) ⇒ Object
> grabs stats from ancestry.
-
#back_stats(option, aspect) ⇒ Object
> grabs stats from background.
-
#clas_stats(option, aspect) ⇒ Object
> grabs stats from class.
- #confirm(option, aspect) ⇒ Object
- #hasher(aspect, header) ⇒ Object
-
#initialize ⇒ Archivist
constructor
A new instance of Archivist.
- #page_finder(aspect) ⇒ Object
-
#summarize(option, aspect) ⇒ Object
> grabs flavor blurb.
Constructor Details
#initialize ⇒ Archivist
Returns a new instance of Archivist.
30 31 32 33 34 |
# File 'lib/Archivist.rb', line 30 def initialize @ancestries = hasher(:ancestries, "h2") @backgrounds = hasher(:backgrounds, "h1") @classes = hasher(:classes, "h1") end |
Instance Attribute Details
#ancestries ⇒ Object (readonly)
Returns the value of attribute ancestries.
6 7 8 |
# File 'lib/Archivist.rb', line 6 def ancestries @ancestries end |
#backgrounds ⇒ Object (readonly)
Returns the value of attribute backgrounds.
6 7 8 |
# File 'lib/Archivist.rb', line 6 def backgrounds @backgrounds end |
#classes ⇒ Object (readonly)
Returns the value of attribute classes.
6 7 8 |
# File 'lib/Archivist.rb', line 6 def classes @classes end |
Instance Method Details
#ance_stats(option, aspect) ⇒ Object
> grabs stats from ancestry
46 47 48 49 50 |
# File 'lib/Archivist.rb', line 46 def ance_stats(option, aspect) # => grabs stats from ancestry page = "https://2e.aonprd.com/"+self.send("#{aspect}")[option] blurb = Nokogiri::HTML(open(page)) blurb.text.match(@@ance_parser) end |
#back_stats(option, aspect) ⇒ Object
> grabs stats from background
52 53 54 55 56 |
# File 'lib/Archivist.rb', line 52 def back_stats(option, aspect) # => grabs stats from background page = "https://2e.aonprd.com/"+self.send("#{aspect}")[option] blurb = Nokogiri::HTML(open(page)) blurb.text.match(@@back_parser) end |
#clas_stats(option, aspect) ⇒ Object
> grabs stats from class
58 59 60 61 62 |
# File 'lib/Archivist.rb', line 58 def clas_stats(option, aspect) # => grabs stats from class page = "https://2e.aonprd.com/"+self.send("#{aspect}")[option] blurb = Nokogiri::HTML(open(page)) blurb.css("b")[2].text.match(@@clas_parser) end |
#confirm(option, aspect) ⇒ Object
64 65 66 67 |
# File 'lib/Archivist.rb', line 64 def confirm(option, aspect) return true if self.send("#{aspect}").include?(option) puts "Choose from the list of #{aspect} above." end |
#hasher(aspect, header) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/Archivist.rb', line 20 def hasher(aspect, header) dictionary = {} page_finder(aspect).css("#{header} a").each{ |role| if role.attribute("href").value.include?("#{aspect.to_s.capitalize}.aspx?ID") dictionary[role.text] = role.attribute("href").value end } dictionary end |
#page_finder(aspect) ⇒ Object
16 17 18 |
# File 'lib/Archivist.rb', line 16 def page_finder(aspect) Nokogiri::HTML(open(@@source+aspect.to_s.capitalize+'.aspx')) end |
#summarize(option, aspect) ⇒ Object
> grabs flavor blurb
36 37 38 39 40 41 42 43 44 |
# File 'lib/Archivist.rb', line 36 def summarize(option, aspect) # => grabs flavor blurb page = "https://2e.aonprd.com/"+self.send("#{aspect}")[option] blurb = Nokogiri::HTML(open(page)) if page.include?("Backgrounds") puts blurb.text.match(/pg. 6\d(.+)Choose/)[1] else puts blurb.css("i")[1].text end end |