Class: Makimono::Resource
- Inherits:
-
Object
- Object
- Makimono::Resource
- Defined in:
- lib/makimono/resource.rb
Direct Known Subclasses
Constant Summary collapse
- ORDERED_BASENAME_REGEXP =
/\A(?<number>\d+)-(?<title>.+)\z/.freeze
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #basename ⇒ Object
- #basename=(new_basename) ⇒ Object
- #dirname ⇒ Object
- #extname ⇒ Object
- #extname=(new_extname) ⇒ Object
-
#initialize(path, content) ⇒ Resource
constructor
A new instance of Resource.
- #number ⇒ Object
- #ordered? ⇒ Boolean
- #title ⇒ Object
Constructor Details
#initialize(path, content) ⇒ Resource
Returns a new instance of Resource.
10 11 12 13 |
# File 'lib/makimono/resource.rb', line 10 def initialize(path, content) self.path = path @content = content end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
8 9 10 |
# File 'lib/makimono/resource.rb', line 8 def content @content end |
#path ⇒ Object
Returns the value of attribute path.
7 8 9 |
# File 'lib/makimono/resource.rb', line 7 def path @path end |
Instance Method Details
#basename ⇒ Object
23 24 25 |
# File 'lib/makimono/resource.rb', line 23 def basename File.basename(path, '.*') end |
#basename=(new_basename) ⇒ Object
27 28 29 |
# File 'lib/makimono/resource.rb', line 27 def basename=(new_basename) self.path = "#{dirname}/#{new_basename}#{extname}" end |
#dirname ⇒ Object
19 20 21 |
# File 'lib/makimono/resource.rb', line 19 def dirname File.dirname(path) end |
#extname ⇒ Object
31 32 33 |
# File 'lib/makimono/resource.rb', line 31 def extname File.extname(path) end |
#extname=(new_extname) ⇒ Object
35 36 37 |
# File 'lib/makimono/resource.rb', line 35 def extname=(new_extname) self.path = "#{dirname}/#{basename}#{new_extname}" end |
#number ⇒ Object
43 44 45 |
# File 'lib/makimono/resource.rb', line 43 def number basename[ORDERED_BASENAME_REGEXP, :number]&.to_i end |
#ordered? ⇒ Boolean
39 40 41 |
# File 'lib/makimono/resource.rb', line 39 def ordered? basename.match?(ORDERED_BASENAME_REGEXP) end |
#title ⇒ Object
47 48 49 |
# File 'lib/makimono/resource.rb', line 47 def title basename[ORDERED_BASENAME_REGEXP, :title] end |