diff options
| author | mo khan <mo@mokhan.ca> | 2014-02-21 20:51:30 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2014-02-21 20:51:30 -0700 |
| commit | ea2de48ec543fb341be31e9ed312b72ede860aee (patch) | |
| tree | 7629790c8aa8e46a73de1e58d13baf8dd6324aca /app | |
| parent | 57170cae301215b992f398853732d00e7efe3119 (diff) | |
inplement query method to find matching status strategy.
Diffstat (limited to 'app')
| -rw-r--r-- | app/models/license_status.rb | 4 | ||||
| -rw-r--r-- | app/models/license_status/active.rb | 4 | ||||
| -rw-r--r-- | app/models/license_status/confidential.rb | 4 | ||||
| -rw-r--r-- | app/models/license_status/expired.rb | 4 |
4 files changed, 14 insertions, 2 deletions
diff --git a/app/models/license_status.rb b/app/models/license_status.rb index 998792f..41b54c5 100644 --- a/app/models/license_status.rb +++ b/app/models/license_status.rb @@ -5,7 +5,7 @@ class LicenseStatus ALL=[ACTIVE, EXPIRED, CONFIDENTIAL] - def self.find_match(status) - ACTIVE + def self.find_match(status = "") + ALL.find { |x| x.matches?("#{status}".downcase) } || ACTIVE end end diff --git a/app/models/license_status/active.rb b/app/models/license_status/active.rb index 80d950d..76fb4c0 100644 --- a/app/models/license_status/active.rb +++ b/app/models/license_status/active.rb @@ -3,5 +3,9 @@ class LicenseStatus::Active today = DateTime.now licenses.where('issued_at < ? AND expired_at > ?', today, today) end + + def matches?(name) + "active" == name + end end diff --git a/app/models/license_status/confidential.rb b/app/models/license_status/confidential.rb index f3e980a..81178f6 100644 --- a/app/models/license_status/confidential.rb +++ b/app/models/license_status/confidential.rb @@ -2,4 +2,8 @@ class LicenseStatus::Confidential def filter(licenses) licenses.where(confidential: true) end + + def matches?(name) + "confidential" == name + end end diff --git a/app/models/license_status/expired.rb b/app/models/license_status/expired.rb index 1b339c6..393e34f 100644 --- a/app/models/license_status/expired.rb +++ b/app/models/license_status/expired.rb @@ -3,4 +3,8 @@ class LicenseStatus::Expired today = DateTime.now licenses.where('expired_at < ?', today) end + + def matches?(name) + "expired" == name + end end |
