Class: AdManagerApi::AdManagerDate
- Inherits:
-
Object
- Object
- AdManagerApi::AdManagerDate
- Defined in:
- lib/ad_manager_api/ad_manager_api_datetime.rb
Class Method Summary collapse
-
.today(api, *args) ⇒ Object
Creates an AdManagerDate object denoting the present day.
Instance Method Summary collapse
-
#initialize(api, *args) ⇒ AdManagerDate
constructor
Create a new AdManagerDate, a utility class that allows for interoperability between the Ad Manager API’s Date objects and ruby’s Date class.
-
#method_missing(name, *args, &block) ⇒ Object
When an unrecognized method is applied to AdManagerDate, pass it through to the internal ruby Date.
-
#to_date ⇒ Object
Convert AdManagerDate into a native ruby Date object.
-
#to_h ⇒ Object
Convert AdManagerDate into a hash representation which can be consumed by the Ad Manager API.
Constructor Details
#initialize(api, *args) ⇒ AdManagerDate
Create a new AdManagerDate, a utility class that allows for interoperability between the Ad Manager API’s Date objects and ruby’s Date class.
Args:
- args:
- ([year, [month, [day]]]), integer values, uses Date defaults
- (date), a native ruby Date object
- (ad_manager_date), an Ad Manager Date hash representation
Returns:
- ad_manager_date: an instance of AdManagerDate
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ad_manager_api/ad_manager_api_datetime.rb', line 38 def initialize(api, *args) @api = api @api.utils_reporter.ad_manager_date_used() case args.first when Hash hash = args.first date_args = [hash[:year], hash[:month], hash[:day]] when Date date = args.first date_args = [date.year, date.month, date.day] else date_args = args end @date = Date.new(*date_args) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
When an unrecognized method is applied to AdManagerDate, pass it through to the internal ruby Date.
62 63 64 65 66 |
# File 'lib/ad_manager_api/ad_manager_api_datetime.rb', line 62 def method_missing(name, *args, &block) result = @date.send(name, *args, &block) return self.class.new(@api, result) if result.is_a? Date return result end |
Class Method Details
.today(api, *args) ⇒ Object
Creates an AdManagerDate object denoting the present day.
56 57 58 |
# File 'lib/ad_manager_api/ad_manager_api_datetime.rb', line 56 def self.today(api, *args) self.new(api, Date.today(*args)) end |
Instance Method Details
#to_date ⇒ Object
Convert AdManagerDate into a native ruby Date object.
78 79 80 |
# File 'lib/ad_manager_api/ad_manager_api_datetime.rb', line 78 def to_date() return Date.new(@date.year, @date.month, @date.day) end |
#to_h ⇒ Object
Convert AdManagerDate into a hash representation which can be consumed by the Ad Manager API. E.g., a hash that can be passed as PQL Date variables.
Returns:
- ad_manager_datetime: an Ad Manager Date hash representation
73 74 75 |
# File 'lib/ad_manager_api/ad_manager_api_datetime.rb', line 73 def to_h() return {:year => @date.year, :month => @date.month, :day => @date.day} end |