Class: Releases::Instance
- Inherits:
-
Object
- Object
- Releases::Instance
- Extended by:
- Forwardable
- Includes:
- Padrino::Helpers::FormatHelpers
- Defined in:
- lib/releases/instance.rb
Instance Attribute Summary collapse
-
#controller ⇒ Object
Returns the value of attribute controller.
-
#resource ⇒ Object
Returns the value of attribute resource.
-
#tag ⇒ Object
Returns the value of attribute tag.
Class Method Summary collapse
Instance Method Summary collapse
- #body ⇒ Object
- #date ⇒ Object
-
#initialize(controller, resource, attributes = {}) ⇒ Instance
constructor
A new instance of Instance.
- #matrix ⇒ Object
- #teaser ⇒ Object
- #title ⇒ Object
- #version ⇒ Object
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
#controller ⇒ Object
Returns the value of attribute controller.
10 11 12 |
# File 'lib/releases/instance.rb', line 10 def controller @controller end |
#resource ⇒ Object
Returns the value of attribute resource.
10 11 12 |
# File 'lib/releases/instance.rb', line 10 def resource @resource end |
#tag ⇒ Object
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
#body ⇒ Object
33 34 35 |
# File 'lib/releases/instance.rb', line 33 def body resource.render(layout: false) end |
#date ⇒ Object
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 |
#matrix ⇒ Object
41 42 43 |
# File 'lib/releases/instance.rb', line 41 def matrix data.fetch(:versions, {}) end |
#teaser ⇒ Object
37 38 39 |
# File 'lib/releases/instance.rb', line 37 def truncate_words((body), length: 15) end |
#title ⇒ Object
29 30 31 |
# File 'lib/releases/instance.rb', line 29 def title data[:title].presence || tag end |
#version ⇒ Object
45 46 47 |
# File 'lib/releases/instance.rb', line 45 def version tag.gsub("v", "") end |