Sha256: f8335a127df455119dfb7ae583a95b124c0bec3999d5503a7079e6697fa1aba6

Contents?: true

Size: 850 Bytes

Versions: 10

Compression:

Stored size: 850 Bytes

Contents

module Listings
  class BaseFieldView
    attr_reader :field
    attr_reader :listing

    def initialize(listing, field_description)
      @listing = listing
      @field_description = field_description
      @field = if @field_description.is_field?
        @field_description.build_field(listing)
      else
        nil
      end
    end

    def path
      @field_description.path
    end

    def human_name
      return @field_description.props[:title] if @field_description.props[:title]
      return path if path.is_a?(String)

      I18n.t("listings.headers.#{listing.name}.#{key}", default: listing.human_name(field))
    end

    def key
      if @field
        @field.key
      else
        path
      end
    end

    def is_field?
      @field_description.is_field?
    end

    def descriptor
      @field_description
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
listings-0.1.15 lib/listings/base_field_view.rb
listings-0.1.14 lib/listings/base_field_view.rb
listings-0.1.13 lib/listings/base_field_view.rb
listings-0.1.12 lib/listings/base_field_view.rb
listings-0.1.11 lib/listings/base_field_view.rb
listings-0.1.10 lib/listings/base_field_view.rb
listings-0.1.8 lib/listings/base_field_view.rb
listings-0.1.7 lib/listings/base_field_view.rb
listings-0.1.6 lib/listings/base_field_view.rb
listings-0.1.5 lib/listings/base_field_view.rb