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
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Instance Method Summary collapse
-
#body ⇒ String
(also: #to_s)
The actual story, including MediaWiki markup.
- #credits ⇒ Object
- #date ⇒ ::Date?
- #geekiness ⇒ Object
- #header?(key) ⇒ Boolean
-
#headers ⇒ Hash<String, String>
The story’s metadata.
-
#initialize(file) ⇒ Fable
constructor
A new instance of Fable.
- #lang ⇒ Symbol
- #names ⇒ Object
- #number ⇒ Object
-
#read_headers? ⇒ Object
Returns the value of attribute read_headers.
- #tagline ⇒ Object
- #title ⇒ Object
- #topics ⇒ Object
- #translator ⇒ Object
Constructor Details
#initialize(file) ⇒ Fable
Returns a new instance of Fable.
31 32 33 34 35 |
# File 'lib/codeless_code/fable.rb', line 31 def initialize(file) @file = file @read_headers = false @body_pos = nil end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
26 27 28 |
# File 'lib/codeless_code/fable.rb', line 26 def file @file end |
Instance Method Details
#body ⇒ String Also known as: to_s
Returns the actual story, including MediaWiki markup.
38 39 40 |
# File 'lib/codeless_code/fable.rb', line 38 def body @body ||= read_body.freeze end |
#credits ⇒ Object
77 78 79 |
# File 'lib/codeless_code/fable.rb', line 77 def credits self['Credits'] end |
#date ⇒ ::Date?
56 57 58 |
# File 'lib/codeless_code/fable.rb', line 56 def date ::Date.parse(self['Date']) if header?('Date') end |
#geekiness ⇒ Object
85 86 87 |
# File 'lib/codeless_code/fable.rb', line 85 def geekiness self['Geekiness'].to_i end |
#header?(key) ⇒ Boolean
51 52 53 |
# File 'lib/codeless_code/fable.rb', line 51 def header?(key) headers.key?(key) end |
#headers ⇒ Hash<String, String>
Returns the story’s metadata.
44 45 46 47 48 49 |
# File 'lib/codeless_code/fable.rb', line 44 def headers @headers ||= begin @read_headers = true read_headers.freeze end end |
#lang ⇒ Symbol
61 62 63 |
# File 'lib/codeless_code/fable.rb', line 61 def lang @lang ||= dir_parts.first.to_sym end |
#names ⇒ Object
89 90 91 |
# File 'lib/codeless_code/fable.rb', line 89 def names list('Names') end |
#number ⇒ Object
81 82 83 |
# File 'lib/codeless_code/fable.rb', line 81 def number self['Number'].to_i end |
#read_headers? ⇒ Object
Returns the value of attribute read_headers.
28 29 30 |
# File 'lib/codeless_code/fable.rb', line 28 def read_headers @read_headers end |
#tagline ⇒ Object
73 74 75 |
# File 'lib/codeless_code/fable.rb', line 73 def tagline self['Tagline'] end |
#title ⇒ Object
69 70 71 |
# File 'lib/codeless_code/fable.rb', line 69 def title self['Title'] end |
#topics ⇒ Object
93 94 95 |
# File 'lib/codeless_code/fable.rb', line 93 def topics list('Topics') end |
#translator ⇒ Object
65 66 67 |
# File 'lib/codeless_code/fable.rb', line 65 def translator @translator ||= dir_parts.last end |