Class: Khaleesi::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/khaleesi/generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(page_file, page_variables) ⇒ Page

Returns a new instance of Page.



586
587
588
589
# File 'lib/khaleesi/generator.rb', line 586

def initialize(page_file, page_variables)
  @page_file = File.expand_path(page_file)
  @page_variables = page_variables
end

Instance Method Details

#<=>(other) ⇒ Object



591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
# File 'lib/khaleesi/generator.rb', line 591

def <=> (other)
  regexp = /^sequence(\p{Blank}?):(\p{Blank}?)(\d+)$/

  self_sequence = @page_variables[regexp, 3] if @page_variables
  o_variables = other.instance_variable_get(:@page_variables)
  other_sequence = o_variables[regexp, 3] if o_variables

  # if which one specify sequence, we shall force comparing by sequence.
  if self_sequence || other_sequence
    self_sequence = self_sequence.to_i
    other_sequence = other_sequence.to_i

    return 1 if self_sequence < other_sequence
    return 0 if self_sequence == other_sequence
    return -1 if self_sequence > other_sequence
  end


  other_create_time = other.take_create_time
  self_create_time = take_create_time
  other_create_time <=> self_create_time
end

#take_create_timeObject



615
616
617
618
619
# File 'lib/khaleesi/generator.rb', line 615

def take_create_time
  # cache the create time to improve performance while sorting by.
  return @create_time if @create_time
  @create_time = Generator.fetch_create_time(@page_file)
end

#to_sObject



621
622
623
# File 'lib/khaleesi/generator.rb', line 621

def to_s
  @page_file
end