Sha256: 730b465ac0421267f51eb64d644a5955e867ae0f99f78ec94a8e9a25c9087809

Contents?: true

Size: 792 Bytes

Versions: 3

Compression:

Stored size: 792 Bytes

Contents

class Storys::Story
  attr_reader :storys
  attr_reader :path, :nsf

  def initialize(storys, path)
    @storys = storys
    @path = path
    @nsf = Nsf::Document.from_html(File.read(@path))
  end

  def path_hash
    Digest::SHA256.hexdigest(path.to_s)[0..16]
  end

  def url
    storys.pathname_to_url(path, storys.storys_path)
  end

  def title
    title = nsf.title 
    title = path.basename.to_s.chomp(path.extname.to_s) if title == ""
    title
  end

  def self.from_hash(storys, data)
    Storys::Story.new(storys, storys.url_to_pathname(Addressable::URI.parse(data["url"])))
  end

  def to_hash
    {
      "url" => url,
      "wordCount" => nsf.to_nsf.split(/\s+/).length,
      "title" => title,
      "publishedOn" => path.mtime.to_i,
      "key" => path_hash
    }
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
storys-0.0.3 lib/storys/story.rb
storys-0.0.2 lib/storys/story.rb
storys-0.0.1 lib/storys/story.rb