Class: ATDIS::Models::Info

Inherits:
ATDIS::Model show all
Defined in:
lib/atdis/models/info.rb

Instance Attribute Summary

Attributes inherited from ATDIS::Model

#attributes, #attributes_before_type_cast, #json_left_overs, #json_load_error, #url

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ATDIS::Model

attribute_keys, attribute_names, cast, #initialize, interpret, #json_errors, #json_errors_in_children, #json_errors_local, #json_left_overs_is_empty, #json_loaded_correctly!, partition_by_used, read_json, read_url, #used_attribute?

Constructor Details

This class inherits a constructor from ATDIS::Model

Class Method Details

.url_encoded?(s) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
65
66
67
68
69
70
71
# File 'lib/atdis/models/info.rb', line 62

def self.url_encoded?(s)
  url_encoded = true
  s.each_char do |c|
    # These characters are the valid ones in a url encoded string
    unless c =~ /[a-zA-Z0-9\-_.~%+]/
      url_encoded = false
    end
  end
  url_encoded
end

Instance Method Details

#dat_id_is_url_encoded!Object

TODO Validate contents of estimated_cost



56
57
58
59
60
# File 'lib/atdis/models/info.rb', line 56

def dat_id_is_url_encoded!
  if dat_id && !Info.url_encoded?(dat_id)
    errors.add(:dat_id, ErrorMessage.new("should be url encoded", "4.3.1"))
  end
end

#notification_dates_consistent!Object



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/atdis/models/info.rb', line 79

def notification_dates_consistent!
  if notification_start_date_before_type_cast && notification_end_date_before_type_cast.blank?
    errors.add(:notification_end_date, ErrorMessage["can not be blank if notification_start_date is set", "4.3.1"])
  end
  if notification_start_date_before_type_cast.blank? && notification_end_date_before_type_cast
    errors.add(:notification_start_date, ErrorMessage["can not be blank if notification_end_date is set", "4.3.1"])
  end
  if notification_start_date && notification_end_date && notification_start_date > notification_end_date
    errors.add(:notification_end_date, ErrorMessage["can not be earlier than notification_start_date", "4.3.1"])
  end
end


73
74
75
76
77
# File 'lib/atdis/models/info.rb', line 73

def related_apps_url_format
  if related_apps.respond_to?(:all?) && !related_apps.all? {|url| url.to_s =~ /atdis\/1.0\/[^\/]+\.json/}
    errors.add(:related_apps, ErrorMessage.new("contains url(s) not in the expected format", "4.3.1"))
  end
end