Sha256: a126e2c11433bcf921aabe01696ec4377795392a6f583859915bcfe681eb0e1f

Contents?: true

Size: 510 Bytes

Versions: 4

Compression:

Stored size: 510 Bytes

Contents

module Crystal
  class Tag < Struct.new(:name, :value)
    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

4 entries across 4 versions & 1 rubygems

Version Path
crystalmeta-0.9.3 lib/crystal/tag.rb
crystalmeta-0.9.2 lib/crystal/tag.rb
crystalmeta-0.9.1 lib/crystal/tag.rb
crystalmeta-0.9.0 lib/crystal/tag.rb