Class: Servel::Entry

Inherits:
Object
  • Object
show all
Extended by:
Instrumentation
Defined in:
lib/servel/entry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Instrumentation

instrument

Constructor Details

#initialize(ftype:, type:, media_type: nil, listing_classes:, icon:, href:, name:, size: nil, mtime: nil) ⇒ Entry

Returns a new instance of Entry.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/servel/entry.rb', line 6

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

Instance Attribute Details

#ftypeObject (readonly)

Returns the value of attribute ftype.



4
5
6
# File 'lib/servel/entry.rb', line 4

def ftype
  @ftype
end

#hrefObject (readonly)

Returns the value of attribute href.



4
5
6
# File 'lib/servel/entry.rb', line 4

def href
  @href
end

#iconObject (readonly)

Returns the value of attribute icon.



4
5
6
# File 'lib/servel/entry.rb', line 4

def icon
  @icon
end

#listing_classesObject (readonly)

Returns the value of attribute listing_classes.



4
5
6
# File 'lib/servel/entry.rb', line 4

def listing_classes
  @listing_classes
end

#media_typeObject (readonly)

Returns the value of attribute media_type.



4
5
6
# File 'lib/servel/entry.rb', line 4

def media_type
  @media_type
end

#mtimeObject (readonly)

Returns the value of attribute mtime.



4
5
6
# File 'lib/servel/entry.rb', line 4

def mtime
  @mtime
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/servel/entry.rb', line 4

def name
  @name
end

#sizeObject (readonly)

Returns the value of attribute size.



4
5
6
# File 'lib/servel/entry.rb', line 4

def size
  @size
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/servel/entry.rb', line 4

def type
  @type
end

Instance Method Details

#as_jsonObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/servel/entry.rb', line 30

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? ? "-" : @size,
    mtime: @mtime.to_i,
    mtimeText: @mtime.nil? ? "-" : @mtime.strftime("%e %b %Y %l:%M %p"),
    media: media?
  }
end

#directory?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/servel/entry.rb', line 18

def directory?
  @ftype == :directory
end

#file?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/servel/entry.rb', line 22

def file?
  @ftype == :file
end

#media?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/servel/entry.rb', line 26

def media?
  !@media_type.nil?
end