Class: Shop::Container
Constant Summary
Constants inherited from Exist
Instance Attribute Summary collapse
-
#cache ⇒ Object
Returns the value of attribute cache.
-
#containers ⇒ Object
Returns the value of attribute containers.
-
#id ⇒ Object
Returns the value of attribute id.
-
#nested ⇒ Object
Returns the value of attribute nested.
-
#props ⇒ Object
Returns the value of attribute props.
-
#show ⇒ Object
Returns the value of attribute show.
Attributes inherited from Exist
Instance Method Summary collapse
- #action(verb) ⇒ Object
-
#at ⇒ Object
detect nested containers.
- #contents ⇒ Object
- #in ⇒ Object
-
#initialize(obj) ⇒ Container
constructor
A new instance of Container.
- #look ⇒ Object
- #nested? ⇒ Boolean
- #on ⇒ Object
- #to_s ⇒ Object
Methods inherited from Exist
#==, #deconstruct_keys, #effects, #exists?, #fetch, fetch, #gone?, #method_missing, normalize_type_data, #respond_to_missing?, scan, #tags, #to_h
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Exist
Instance Attribute Details
#cache ⇒ Object
Returns the value of attribute cache.
31 32 33 |
# File 'lib/Olib/shops.rb', line 31 def cache @cache end |
#containers ⇒ Object
Returns the value of attribute containers.
31 32 33 |
# File 'lib/Olib/shops.rb', line 31 def containers @containers end |
#id ⇒ Object
Returns the value of attribute id.
31 32 33 |
# File 'lib/Olib/shops.rb', line 31 def id @id end |
#nested ⇒ Object
Returns the value of attribute nested.
31 32 33 |
# File 'lib/Olib/shops.rb', line 31 def nested @nested end |
#props ⇒ Object
Returns the value of attribute props.
31 32 33 |
# File 'lib/Olib/shops.rb', line 31 def props @props end |
#show ⇒ Object
Returns the value of attribute show.
31 32 33 |
# File 'lib/Olib/shops.rb', line 31 def show @show end |
Instance Method Details
#action(verb) ⇒ Object
48 49 50 |
# File 'lib/Olib/shops.rb', line 48 def action(verb) "#{verb} ##{@id}" end |
#at ⇒ Object
detect nested containers
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/Olib/shops.rb', line 57 def at Olib.wrap_stream(action 'look at') { |line| raise Errors::Mundane if line =~ /You see nothing unusual/ if line =~ /Looking at the (.*?), you see (?<nested>.*)/ @nested = true @containers = line.match(/Looking at the (.*?), you see (?<nested>.*)/)[:nested].scan(/<a exist="(?<id>.*?)" noun="(?<noun>.*?)">(?<name>.*?)<\/a>/).map {|matches| Container.new GameObj.new *matches } raise Errors::Prempt end } self end |
#contents ⇒ Object
99 100 101 102 |
# File 'lib/Olib/shops.rb', line 99 def contents look.in.on unless GameObj[@id].contents GameObj[@id].contents.map {|i| Item.new(i).define('container', @id) } end |
#in ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/Olib/shops.rb', line 81 def in return self unless @id Olib.wrap_stream(action 'look in') { |line| raise Errors::Mundane if line=~ /^There is nothing in there|^That is closed|filled with a variety of garbage|Total items:/ raise Errors::Prempt if line =~ /^In the (.*?) you see/ } self end |
#look ⇒ Object
52 53 54 |
# File 'lib/Olib/shops.rb', line 52 def look self end |
#nested? ⇒ Boolean
77 78 79 |
# File 'lib/Olib/shops.rb', line 77 def nested? @nested || false end |
#on ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/Olib/shops.rb', line 90 def on return self unless @id Olib.wrap_stream(action 'look on') { |line| raise Errors::Mundane if line =~ /^There is nothing on there/ raise Errors::Prempt if line =~ /^On the (.*?) you see/ } self end |
#to_s ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/Olib/shops.rb', line 33 def to_s info = {} info[:name] = @name info[:noun] = @noun info[:props] = @props info[:cache] = @cache info.to_s end |