Sha256: 050fe4f79bd778801f88b6c6014f7b0b51bca0621c8ef5a029fec9e62126bd9d

Contents?: true

Size: 587 Bytes

Versions: 1

Compression:

Stored size: 587 Bytes

Contents

module Crystal
  class Tag < Struct.new(:name, :value)
    def name_key
      name.starts_with?('og:') ? :property : :name
    end

    def value_for_context(context)
      case
      when asset?
        context.send(asset_path_method, value)
      when value.acts_like?(:time)
        value.iso8601
      when value.acts_like?(:date)
        value.strftime('%Y-%m-%d')
      else
        value
      end
    end

    private

    def asset?
      %w{image audio video}.find{|type| name =~ /\b#{type}(:url)?$/}
    end

    def asset_path_method
      "#{asset?}_path"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
crystalmeta-0.9.4 lib/crystal/tag.rb