diff options
author | Nat Lasseter <Nat Lasseter nathan@bytemark.co.uk> | 2018-04-04 21:54:03 +0100 |
---|---|---|
committer | Nat Lasseter <Nat Lasseter nathan@bytemark.co.uk> | 2018-04-04 21:54:03 +0100 |
commit | c7f7a60a7f1175696b8239355dc7737532c1f1ce (patch) | |
tree | fe5759a74286560e0da63208fdb0424098fe810c /parse.rb |
Diffstat (limited to 'parse.rb')
-rw-r--r-- | parse.rb | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/parse.rb b/parse.rb new file mode 100644 index 0000000..f81d509 --- /dev/null +++ b/parse.rb @@ -0,0 +1,74 @@ +exit 1 if ARGV.empty? + +$things = [] +$rooms = [] + +class ThingFactory + def self.create_thing(block) + ThingFactory.new(block).to_thing + end + + def initialize(block) + @name = "" + @properties = [] + @energy = 0 + self.instance_eval(&block) + end + + def name(str) + @name = str + end + + def property(str, *strs) + @properties << str + @properties += strs + end + + def energy(num) + @energy = num + end + + def to_thing + return Thing.new(@name, @properties, @energy) + end +end + +class Thing + def self.parse(block) + return ThingFactory.create_thing(block) + end + + def initialize(name, properties, energy) + @name = name + @properties = properties + @energy = energy + end + + def has_property(str) + return @properties.include?(str) + end + + def method_missing(name) + if name.to_s =~ /^is_(.*)\?$/ then + has_property($1) + end + end + + attr_reader :name + attr_accessor :energy +end + + + +def room(&block) + #return Room.parse(block) +end + +def thing(&block) + $things << Thing.parse(block) +end + + + + +load ARGV.shift.strip |