Class: LessonsIndexer::Models::Base

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/lessons_indexer/models/base.rb

Direct Known Subclasses

Heading, Lesson

Constant Summary collapse

VERSION_PATTERN =
/(?<minor_major>(?<major>(\d+))(?:\.|-)(?<minor>(\d+)))/i

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_name) ⇒ Base

Returns a new instance of Base.



9
10
11
12
13
14
# File 'lib/lessons_indexer/models/base.rb', line 9

def initialize(file_name)
  @file_name = file_name
  @path = File.expand_path(file_name)
  @major = file_name.match(VERSION_PATTERN)[:major].to_i
  @minor = file_name.match(VERSION_PATTERN)[:minor].to_i
end

Instance Attribute Details

#file_nameObject (readonly)

Returns the value of attribute file_name.



7
8
9
# File 'lib/lessons_indexer/models/base.rb', line 7

def file_name
  @file_name
end

#majorObject (readonly)

Returns the value of attribute major.



7
8
9
# File 'lib/lessons_indexer/models/base.rb', line 7

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



7
8
9
# File 'lib/lessons_indexer/models/base.rb', line 7

def minor
  @minor
end

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/lessons_indexer/models/base.rb', line 7

def path
  @path
end

Instance Method Details

#<=>(other) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/lessons_indexer/models/base.rb', line 16

def <=>(other)
  if self.major == other.major
    self.minor <=> other.minor
  else
    self.major <=> other.major
  end
end