Class: Bismas::Schema
- Inherits:
-
Object
- Object
- Bismas::Schema
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/bismas/schema.rb
Constant Summary collapse
- FIELD_RE =
%r{\Afeld\s+=\s+(\d+)}i
- CATEGORY_RE =
lambda { |category_length| %r{\A(.{#{category_length}})"(.+?)"} }
Instance Attribute Summary collapse
-
#category_length ⇒ Object
Returns the value of attribute category_length.
-
#name ⇒ Object
Returns the value of attribute name.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Schema
constructor
A new instance of Schema.
- #parse(io) ⇒ Object
Constructor Details
#initialize ⇒ Schema
Returns a new instance of Schema.
55 56 57 |
# File 'lib/bismas/schema.rb', line 55 def initialize @title, @name, @category_length, @categories = nil, nil, nil, {} end |
Instance Attribute Details
#category_length ⇒ Object
Returns the value of attribute category_length.
59 60 61 |
# File 'lib/bismas/schema.rb', line 59 def category_length @category_length end |
#name ⇒ Object
Returns the value of attribute name.
59 60 61 |
# File 'lib/bismas/schema.rb', line 59 def name @name end |
#title ⇒ Object
Returns the value of attribute title.
59 60 61 |
# File 'lib/bismas/schema.rb', line 59 def title @title end |
Class Method Details
.parse(*args) ⇒ Object
44 45 46 |
# File 'lib/bismas/schema.rb', line 44 def parse(*args) new.parse(*args) end |
.parse_file(file, options = {}) ⇒ Object
48 49 50 51 |
# File 'lib/bismas/schema.rb', line 48 def parse_file(file, = {}) Bismas.amend_encoding() File.open(file, 'rb', , &method(:parse)) end |
Instance Method Details
#parse(io) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/bismas/schema.rb', line 65 def parse(io) category_re = nil io.each { |line| case line when category_re self[$1.strip] = $2.strip when FIELD_RE category_re = CATEGORY_RE[ self.category_length = $1.to_i] when String title ? name ? nil : self.name = line.strip : self.title = line.strip end } self end |