Sha256: 5d5a4c7a32eee8c8445917f6ace7364b4eb35ef22aa70f044f20710f43895bc2

Contents?: true

Size: 878 Bytes

Versions: 5

Compression:

Stored size: 878 Bytes

Contents

module DNote

  #
  class Note
    attr :file
    attr :label
    attr :line
    attr :text

    def initialize(file, label, line, text)
      @file  = file
      @label = label
      @line  = line
      @text  = text.rstrip
    end

    #
    def to_s
      "#{label}: #{text}"
    end

    #
    def to_str
      "#{label}: #{text}"
    end

    #
    def textline
      text.gsub("\n", " ")
    end

    # Sort by file name and line number.
    def <=>(other)
      s = file <=> other.file
      return s unless s == 0
      line <=> other.line
    end

    def to_h
      { 'label'=>label, 'text'=>textline, 'file'=>file, 'line'=>line }
    end

    def to_h_raw
      { 'label'=>label, 'text'=>text, 'file'=>file, 'line'=>line }
    end

    def to_json(*args)
      to_h_raw.to_json(*args)
    end

    def to_yaml(*args)
      to_h_raw.to_yaml(*args)
    end
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dnote-1.4.0 lib/dnote/note.rb
dnote-1.3.1 lib/dnote/note.rb
dnote-1.3.0 lib/dnote/note.rb
dnote-1.2.1 lib/dnote/note.rb
dnote-1.2.0 lib/dnote/note.rb