Class: Releases::Instance

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Padrino::Helpers::FormatHelpers
Defined in:
lib/releases/instance.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller, resource, attributes = {}) ⇒ Instance

Returns a new instance of Instance.



20
21
22
23
24
25
26
27
# File 'lib/releases/instance.rb', line 20

def initialize(controller, resource, attributes = {})
  @controller = controller
  @resource = resource

  attributes.each do |key, value|
    self.public_send("#{ key }=", value)
  end
end

Instance Attribute Details

#controllerObject

Returns the value of attribute controller.



10
11
12
# File 'lib/releases/instance.rb', line 10

def controller
  @controller
end

#resourceObject

Returns the value of attribute resource.



10
11
12
# File 'lib/releases/instance.rb', line 10

def resource
  @resource
end

#tagObject

Returns the value of attribute tag.



10
11
12
# File 'lib/releases/instance.rb', line 10

def tag
  @tag
end

Class Method Details

.from(resource, controller) ⇒ Object



14
15
16
17
18
# File 'lib/releases/instance.rb', line 14

def self.from(resource, controller)
  tag = resource.data[:tag]

  new(controller, resource, tag: tag)
end

Instance Method Details

#bodyObject



33
34
35
# File 'lib/releases/instance.rb', line 33

def body
  resource.render(layout: false)
end

#dateObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/releases/instance.rb', line 49

def date
  return @_date if @_date

  frontmatter_date = data['date']

  # First get the date from frontmatter
  if frontmatter_date.is_a? Time
    @_date = frontmatter_date.in_time_zone
  else
    @_date = Time.zone.parse(frontmatter_date.to_s)
  end

  @_date
end

#matrixObject



41
42
43
# File 'lib/releases/instance.rb', line 41

def matrix
  data.fetch(:versions, {})
end

#teaserObject



37
38
39
# File 'lib/releases/instance.rb', line 37

def teaser
  truncate_words(strip_tags(body), length: 15)
end

#titleObject



29
30
31
# File 'lib/releases/instance.rb', line 29

def title
  data[:title].presence || tag
end

#versionObject



45
46
47
# File 'lib/releases/instance.rb', line 45

def version
  tag.gsub("v", "")
end