Sha256: 659cd8c830e6e75f781b468a1b20b765d2fa0109352da0b880cfa10b378118ed

Contents?: true

Size: 1.02 KB

Versions: 9

Compression:

Stored size: 1.02 KB

Contents

class Servel::Entry
  extend Servel::Instrumentation

  attr_reader :ftype, :type, :media_type, :listing_classes, :icon, :href, :name, :size, :mtime

  def initialize(ftype:, type:, media_type: nil, listing_classes:, icon:, href:, name:, size: nil, mtime: nil)
    @ftype = ftype
    @type = type
    @media_type = media_type
    @listing_classes = listing_classes
    @icon = icon
    @href = href
    @name = name
    @size = size
    @mtime = mtime
  end

  def directory?
    @ftype == :directory
  end

  def file?
    @ftype == :file
  end

  def media?
    !@media_type.nil?
  end

  def as_json(*)
    {
      icon: @icon,
      href: Rack::Utils.escape_path(@href),
      class: @listing_classes,
      mediaType: @media_type,
      name: @name,
      type: @type,
      size: @size.to_i,
      sizeText: @size.nil? ? "-" : ActiveSupport::NumberHelper.number_to_human_size(@size),
      mtime: @mtime.to_i,
      mtimeText: @mtime.nil? ? "-" : @mtime.strftime("%e %b %Y %l:%M %p"),
      media: media?
    }
  end

  instrument :as_json
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
servel-0.33.0 lib/servel/entry.rb
servel-0.32.0 lib/servel/entry.rb
servel-0.31.0 lib/servel/entry.rb
servel-0.30.0 lib/servel/entry.rb
servel-0.29.0 lib/servel/entry.rb
servel-0.28.0 lib/servel/entry.rb
servel-0.27.0 lib/servel/entry.rb
servel-0.26.0 lib/servel/entry.rb
servel-0.25.0 lib/servel/entry.rb