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.



10
11
12
13
# File 'lib/makimono/resource.rb', line 10

def initialize(path, content)
  self.path = path
  @content = content
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



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

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



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

#dirnameObject



19
20
21
# File 'lib/makimono/resource.rb', line 19

def dirname
  File.dirname(path)
end

#extnameObject



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

#numberObject



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

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

#ordered?Boolean

Returns:

  • (Boolean)


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

def ordered?
  basename.match?(ORDERED_BASENAME_REGEXP)
end

#titleObject



47
48
49
# File 'lib/makimono/resource.rb', line 47

def title
  basename[ORDERED_BASENAME_REGEXP, :title]
end