Class: CodelessCode::Fable
- Inherits:
-
Object
- Object
- CodelessCode::Fable
- Extended by:
- Forwardable
- Defined in:
- lib/codeless_code/fable.rb
Overview
Model/Adapter for a “Codeless Code” fable stored in a text file.
Constant Summary collapse
- HEADER_PATTERN =
/([^:\s]+)\s*:\s*(.+)\s*$/.freeze
- RAW_ATTRS =
%w[Title Tagline Credits].freeze
- INTEGER_ATTRS =
%w[Number Geekiness].freeze
- LIST_ATTRS =
%w[Names Topics].freeze
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#has_read_headers ⇒ Object
(also: #read_headers?)
readonly
Returns the value of attribute has_read_headers.
Instance Method Summary collapse
-
#body ⇒ String
(also: #to_s)
The actual story, including MediaWiki markup.
- #date ⇒ ::Date?
- #header?(key) ⇒ Boolean
-
#headers ⇒ Hash<String, String>
The story's metadata.
-
#initialize(file) ⇒ Fable
constructor
A new instance of Fable.
- #lang ⇒ Symbol
- #translator ⇒ Object
Constructor Details
#initialize(file) ⇒ Fable
37 38 39 40 41 |
# File 'lib/codeless_code/fable.rb', line 37 def initialize(file) @file = file @has_read_headers = false @body_pos = 0 end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file
32 33 34 |
# File 'lib/codeless_code/fable.rb', line 32 def file @file end |
#has_read_headers ⇒ Object (readonly) Also known as: read_headers?
Returns the value of attribute has_read_headers
32 33 34 |
# File 'lib/codeless_code/fable.rb', line 32 def has_read_headers @has_read_headers end |
Instance Method Details
#body ⇒ String Also known as: to_s
44 45 46 |
# File 'lib/codeless_code/fable.rb', line 44 def body @body ||= read_body.freeze end |
#date ⇒ ::Date?
62 63 64 |
# File 'lib/codeless_code/fable.rb', line 62 def date ::Date.parse(self['Date']) if header?('Date') end |
#header?(key) ⇒ Boolean
57 58 59 |
# File 'lib/codeless_code/fable.rb', line 57 def header?(key) headers.key?(key) end |
#headers ⇒ Hash<String, String>
50 51 52 53 54 55 |
# File 'lib/codeless_code/fable.rb', line 50 def headers @headers ||= begin @has_read_headers = true read_headers.freeze end end |
#lang ⇒ Symbol
67 68 69 |
# File 'lib/codeless_code/fable.rb', line 67 def lang @lang ||= dir_parts.first.to_sym end |
#translator ⇒ Object
71 72 73 |
# File 'lib/codeless_code/fable.rb', line 71 def translator @translator ||= dir_parts.last end |