Class: DataKitten::DistributionFormat
- Inherits:
-
Object
- Object
- DataKitten::DistributionFormat
- Defined in:
- lib/data_kitten/distribution_format.rb
Overview
A file format for a distribution
For instance CSV, XML, etc.
Constant Summary collapse
- FORMATS =
{ csv: { structured: true, open: true }, xls: { structured: true, open: false }, xlsx: { structured: true, open: true }, rdf: { structured: true, open: true }, xml: { structured: true, open: true }, wms: { structured: true, open: true }, ods: { structured: true, open: true }, rdfa: { structured: true, open: true }, kml: { structured: true, open: true }, rss: { structured: true, open: true }, json: { structured: true, open: true }, ical: { structured: true, open: true }, sparql: { structured: true, open: true }, kml: { structured: true, open: true }, georss: { structured: true, open: true }, geojson: { structured: true, open: true }, shp: { structured: true, open: true }, html: { structured: false, open: true }, doc: { structured: false, open: false }, pdf: { structured: false, open: true } }
Instance Attribute Summary collapse
-
#extension ⇒ Symbol
A symbol for the file extension.
Instance Method Summary collapse
-
#initialize(distribution) ⇒ DistributionFormat
constructor
Create a new DistributionFormat object with the relevant extension.
-
#matches? ⇒ Boolean
Whether the format of the file matches the extension given by the data.
-
#open? ⇒ Boolean
Is this an open format?.
-
#structured? ⇒ Boolean
Is this a structured format?.
Constructor Details
#initialize(distribution) ⇒ DistributionFormat
Create a new DistributionFormat object with the relevant extension
40 41 42 43 44 |
# File 'lib/data_kitten/distribution_format.rb', line 40 def initialize(distribution) @distribution = distribution # Store extension as a lowercase symbol @extension = distribution.extension.to_s.downcase.to_sym end |
Instance Attribute Details
#extension ⇒ Symbol
Returns a symbol for the file extension. For instance, :csv.
35 36 37 |
# File 'lib/data_kitten/distribution_format.rb', line 35 def extension @extension end |
Instance Method Details
#matches? ⇒ Boolean
Whether the format of the file matches the extension given by the data
63 64 65 66 67 68 69 70 71 |
# File 'lib/data_kitten/distribution_format.rb', line 63 def matches? begin mimes = [] MIME::Types.type_for(@extension.to_s).each { |i| mimes << i.content_type } !!(@distribution.http_head.content_type =~ /#{mimes.join('|')}/) || false rescue nil end end |
#open? ⇒ Boolean
Is this an open format?
56 57 58 |
# File 'lib/data_kitten/distribution_format.rb', line 56 def open? FORMATS[extension][:open] end |
#structured? ⇒ Boolean
Is this a structured format?
49 50 51 |
# File 'lib/data_kitten/distribution_format.rb', line 49 def structured? FORMATS[extension][:structured] end |