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.
9 10 11 12 |
# File 'lib/makimono/resource.rb', line 9 def initialize(path, content) @path = path @content = content end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
7 8 9 |
# File 'lib/makimono/resource.rb', line 7 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
18 19 20 |
# File 'lib/makimono/resource.rb', line 18 def basename File.basename(path, '.*') end |
#basename=(new_basename) ⇒ Object
22 23 24 |
# File 'lib/makimono/resource.rb', line 22 def basename=(new_basename) self.path = "#{dirname}/#{new_basename}#{extname}" end |
#dirname ⇒ Object
14 15 16 |
# File 'lib/makimono/resource.rb', line 14 def dirname File.dirname(path) end |
#extname ⇒ Object
26 27 28 |
# File 'lib/makimono/resource.rb', line 26 def extname File.extname(path) end |
#extname=(new_extname) ⇒ Object
30 31 32 |
# File 'lib/makimono/resource.rb', line 30 def extname=(new_extname) self.path = "#{dirname}/#{basename}#{new_extname}" end |
#number ⇒ Object
38 39 40 |
# File 'lib/makimono/resource.rb', line 38 def number basename[ORDERED_BASENAME_REGEXP, :number]&.to_i end |
#ordered? ⇒ Boolean
34 35 36 |
# File 'lib/makimono/resource.rb', line 34 def ordered? basename.match?(ORDERED_BASENAME_REGEXP) end |
#title ⇒ Object
42 43 44 |
# File 'lib/makimono/resource.rb', line 42 def title basename[ORDERED_BASENAME_REGEXP, :title] end |