class DataKitten::DistributionFormat
A file format for a distribution
For instance CSV, XML, etc.
Constants
- FORMATS
Attributes
extension[R]
@!attribute extension @return [Symbol] a symbol for the file extension. For instance, :csv.
Public Class Methods
new(distribution)
click to toggle source
Create a new DistributionFormat
object with the relevant extension
@param distribution [Distribution] the distribution for the format
# 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
Public Instance Methods
matches?()
click to toggle source
Whether the format of the file matches the extension given by the data
@return [Boolean] whether the MIME type given in the HTTP response matches the data or not
# 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?()
click to toggle source
Is this an open format?
@return [Boolean] whether the format is open or not
# File lib/data_kitten/distribution_format.rb, line 56 def open? FORMATS[extension][:open] end
structured?()
click to toggle source
Is this a structured format?
@return [Boolean] whether the format is machine-readable or not.
# File lib/data_kitten/distribution_format.rb, line 49 def structured? FORMATS[extension][:structured] end