Class: Troy::Meta

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/troy/meta.rb

Constant Summary collapse

REGEX =
/^---\n(.*?)\n---\n+/m.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Meta

Returns a new instance of Meta.



12
13
14
# File 'lib/troy/meta.rb', line 12

def initialize(file)
  @file = file
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *_args) ⇒ Object



25
26
27
# File 'lib/troy/meta.rb', line 25

def method_missing(name, *_args)
  data[name.to_s]
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



10
11
12
# File 'lib/troy/meta.rb', line 10

def file
  @file
end

Instance Method Details

#contentObject



16
17
18
# File 'lib/troy/meta.rb', line 16

def content
  @content ||= raw.gsub(REGEX, "")
end

#dataObject



20
21
22
23
# File 'lib/troy/meta.rb', line 20

def data
  @data ||=
    raw =~ REGEX ? YAML.safe_load(raw[REGEX, 1], [Date, Time]) : {}
end

#rawObject



33
34
35
# File 'lib/troy/meta.rb', line 33

def raw
  @raw ||= File.read(file)
end

#respond_to_missing?(_method, _include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/troy/meta.rb', line 29

def respond_to_missing?(_method, _include_private = false)
  true
end