Class: CodelessCode::Fable

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#fileObject (readonly)

Returns the value of attribute file


32
33
34
# File 'lib/codeless_code/fable.rb', line 32

def file
  @file
end

#has_read_headersObject (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

#bodyString 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

#headersHash<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

#langSymbol


67
68
69
# File 'lib/codeless_code/fable.rb', line 67

def lang
  @lang ||= dir_parts.first.to_sym
end

#translatorObject


71
72
73
# File 'lib/codeless_code/fable.rb', line 71

def translator
  @translator ||= dir_parts.last
end