Permalink
Browse files

Don't parse schemas for each initialization

  • Loading branch information...
1 parent 68f8bc3 commit 921e10d63f27cd3da49be8c3aae2f42608ced21e Anthony Zacharakis committed Apr 5, 2013
Showing with 8 additions and 8 deletions.
  1. +6 −6 lib/paxmex/parser.rb
  2. +2 −2 spec/parser_spec.rb
View
@@ -2,15 +2,15 @@
require 'paxmex/schema'
class Paxmex::Parser
- SCHEMATA = %w(epraw eptrn).reduce({}) { |h, fn| h.merge(fn => YAML::load(File.open("config/#{fn}.yml"))) }
+ SCHEMATA = %w(epraw eptrn).reduce({}) do |h, fn|
+ h.merge(fn => Paxmex::Schema.new(YAML::load(File.open("config/#{fn}.yml"))))
+ end
+
+ attr_reader :schema
def initialize(path, opts = {})
@path = path
- @schema_key = opts[:schema]
- end
-
- def schema
- @schema ||= Paxmex::Schema.new(SCHEMATA[@schema_key])
+ @schema = SCHEMATA[opts[:schema]]
end
def raw
View
@@ -25,15 +25,15 @@
end
it 'returns the schema for the specified key of the eptrn file' do
- parser_eptrn.schema.to_h.should == Paxmex::Parser::SCHEMATA[schema_key_eptrn]
+ parser_eptrn.schema.to_h.should == Paxmex::Parser::SCHEMATA[schema_key_eptrn].to_h
end
it 'returns a schema object for the epraw file' do
parser_epraw.schema.should be_instance_of(Paxmex::Schema)
end
it 'returns the schema for the specified key of the epraw file' do
- parser_epraw.schema.to_h.should == Paxmex::Parser::SCHEMATA[schema_key_epraw]
+ parser_epraw.schema.to_h.should == Paxmex::Parser::SCHEMATA[schema_key_epraw].to_h
end
end

0 comments on commit 921e10d

Please sign in to comment.