Class: Utopia::Gallery::Media
- Inherits:
-
Object
- Object
- Utopia::Gallery::Media
- Defined in:
- lib/utopia/gallery/media.rb
Overview
Represents a single unit of media, e.g. a video or image.
Constant Summary collapse
- ORDER_KEY =
'order'.freeze
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #[](key) ⇒ Object
- #caption ⇒ Object
-
#initialize(path, metadata) ⇒ Media
constructor
A new instance of Media.
- #to_s ⇒ Object
Constructor Details
#initialize(path, metadata) ⇒ Media
Returns a new instance of Media.
26 27 28 29 |
# File 'lib/utopia/gallery/media.rb', line 26 def initialize(path, ) @path = path @metadata = end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
32 33 34 |
# File 'lib/utopia/gallery/media.rb', line 32 def @metadata end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
31 32 33 |
# File 'lib/utopia/gallery/media.rb', line 31 def path @path end |
Instance Method Details
#<=>(other) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/utopia/gallery/media.rb', line 48 def <=> other if a = self[ORDER_KEY] and b = other[ORDER_KEY] a <=> b else self.path <=> other.path end end |
#[](key) ⇒ Object
34 35 36 |
# File 'lib/utopia/gallery/media.rb', line 34 def [] key @metadata[key.to_s] end |
#caption ⇒ Object
38 39 40 |
# File 'lib/utopia/gallery/media.rb', line 38 def @metadata['caption'] end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/utopia/gallery/media.rb', line 42 def to_s || File.basename(@path, ".*") end |