Class: Makimono::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/makimono/resource.rb

Direct Known Subclasses

Style

Constant Summary collapse

ORDERED_BASENAME_REGEXP =
/\A(?<number>\d+)-(?<title>.+)\z/.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#contentObject

Returns the value of attribute content.



7
8
9
# File 'lib/makimono/resource.rb', line 7

def content
  @content
end

#pathObject

Returns the value of attribute path.



7
8
9
# File 'lib/makimono/resource.rb', line 7

def path
  @path
end

Instance Method Details

#basenameObject



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

#dirnameObject



14
15
16
# File 'lib/makimono/resource.rb', line 14

def dirname
  File.dirname(path)
end

#extnameObject



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

#numberObject



38
39
40
# File 'lib/makimono/resource.rb', line 38

def number
  basename[ORDERED_BASENAME_REGEXP, :number]&.to_i
end

#ordered?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/makimono/resource.rb', line 34

def ordered?
  basename.match?(ORDERED_BASENAME_REGEXP)
end

#titleObject



42
43
44
# File 'lib/makimono/resource.rb', line 42

def title
  basename[ORDERED_BASENAME_REGEXP, :title]
end