Sha256: 7aa3dc3e3f98e4f6b651e0d5e2e33bdb3dd52b087e6a9c253ea20a3ced790bc4

Contents?: true

Size: 1.44 KB

Versions: 3

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

require 'bigdecimal'
require 'time'

module Kentaa
  module Api
    module Resources
      class Segment < Resource
        def object_key
          "Segment_#{id}"
        end

        def site_id
          data[:site_id]
        end

        def subdomain
          data[:subdomain]
        end

        def name
          data[:name]
        end

        def title
          data[:title]
        end

        def description
          data[:description]
        end

        def target_amount
          data[:target_amount]
        end

        def total_amount
          BigDecimal(data[:total_amount])
        end

        def total_donations
          data[:total_donations]
        end

        def end_date
          Time.parse(data[:end_date]) if data[:end_date]
        end

        def url
          data[:url]
        end

        def donate_url
          data[:donate_url]
        end

        def banners
          @banners ||= begin
            banners = []

            if data[:banners]
              data[:banners].each do |banner|
                banners << Kentaa::Api::Resources::Banner.new(config, data: banner)
              end
            end

            banners
          end
        end

        def external_reference
          data[:external_reference]
        end

        protected

        def load_resource(options)
          request.get("/segments/#{id}", options)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kentaa-api-0.3.2 lib/kentaa/api/resources/segment.rb
kentaa-api-0.3.1 lib/kentaa/api/resources/segment.rb
kentaa-api-0.3.0 lib/kentaa/api/resources/segment.rb