From ea2de48ec543fb341be31e9ed312b72ede860aee Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 21 Feb 2014 20:51:30 -0700 Subject: inplement query method to find matching status strategy. --- app/models/license_status.rb | 4 ++-- app/models/license_status/active.rb | 4 ++++ app/models/license_status/confidential.rb | 4 ++++ app/models/license_status/expired.rb | 4 ++++ 4 files changed, 14 insertions(+), 2 deletions(-) (limited to 'app') 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 -- cgit v1.2.3