class DayOneKindle::Highlight

Attributes

authors[R]
book[R]
highlight[R]
location[R]
page[R]
time[R]

Public Class Methods

new(options) click to toggle source
# File lib/dayone-kindle/highlight.rb, line 5
def initialize(options)
  # Faking required named arguments for ruby 2.0 compatibility
  %i(book highlight time).each do |param|
    raise ArgumentError, "missing keyword :#{param}" unless options[param]
    instance_variable_set(:"@#{param}", options[param])
  end

  @page = options[:page]
  @location = options[:location]
  @authors = options[:authors] || []
end

Public Instance Methods

to_markdown() click to toggle source
# File lib/dayone-kindle/highlight.rb, line 17
def to_markdown
  [
    markdown_header,
    '',
    markdown_authors,
    '',
    markdown_highlight,
    '',
    markdown_meta
  ].compact.join("\n")
end

Private Instance Methods

markdown_authors() click to toggle source
# File lib/dayone-kindle/highlight.rb, line 35
def markdown_authors
  return if authors.empty?
  "By #{authors.map { |a| "*#{a}*" }.to_sentence}."
end
markdown_header() click to toggle source
# File lib/dayone-kindle/highlight.rb, line 31
def markdown_header
  "# Quote from #{book || 'a book'}"
end
markdown_highlight() click to toggle source
# File lib/dayone-kindle/highlight.rb, line 47
def markdown_highlight
  '> ' + highlight.gsub(/\n/, "\n>")
end
markdown_meta() click to toggle source
# File lib/dayone-kindle/highlight.rb, line 40
def markdown_meta
  meta = []
  meta << "Page #{page}" if page
  meta << "Location #{location}" if location
  meta.join(' - ') unless meta.empty?
end