scooby_snacks 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 228854434b05709dc74c5c33b7aeba6fb15983d3d91917e1a24ef32d2509e523
4
- data.tar.gz: 55471a7d4165a20509d63f416ff25c7dcdd79779fc0b89dd9cc2c5b0fb3d1766
3
+ metadata.gz: 361226b5fb0d156ad6a8bccb9f048d76191d075aa2aa60193062ad490cb11f5c
4
+ data.tar.gz: 73f9eeea08df5835c8a18d5dd6caf738d09fe382b4cf531effd301fae7f5fe4f
5
5
  SHA512:
6
- metadata.gz: 13a899775252d026e4d927e3028533ea6a406d8184cb6068e5003ed95878d24a399d65bdce913d7d4cd6851617171b33b9e57bf45009a55029445d7bb571ba71
7
- data.tar.gz: ed34501d6617d98fbd940bb0f04393db896d10f3fd997d321f46ddc46445fdbf820aa19612b2b36160017ce2ac694413d465106ec0a04daa29f418e2b41195e5
6
+ metadata.gz: ad4d57284a2cbf20abc73b80916812a64e38b7e879839a8acc39f82dfa6dcb10c1077a8f243c8e2cadb82b3483691efb8f953aea682e777764c70a384e5e38f9
7
+ data.tar.gz: cc986ab2032483c5d30be23b3b4a25b8fe7b1ab296a4debccf30ffc91d5825271f7be095f1405dfb4d1cb74100bb64d3190248c9233c1fc2dd9e00f54f5114ed
@@ -105,7 +105,9 @@ module ScoobySnacks
105
105
 
106
106
  def display_options
107
107
  options = {label: label}
108
- if searchable?
108
+ if date?
109
+ options[:render_as] = :date
110
+ elsif searchable?
109
111
  options[:render_as] = :linked
110
112
  options[:search_field] = name
111
113
  end
@@ -50,6 +50,53 @@ module ScoobySnacks
50
50
  SS_DISPLAY_GROUPS + custom_display_groups
51
51
  end
52
52
 
53
+ def self.define_display_group_methods display_groups
54
+ # define methods to list display group contents
55
+ display_groups.each do |display_group|
56
+
57
+ define_method("#{display_group}_display_field_names") do
58
+ field_names = instance_variable_get("@#{display_group}_display_field_names")
59
+ if field_names.nil?
60
+ send("#{display_group}_display_fields".to_sym).map{|field| field.name}
61
+ else
62
+ field_names
63
+ end
64
+ end
65
+
66
+ define_method("#{display_group}_display_fields") do
67
+ field_names = instance_variable_get("@#{display_group}_display_field_names")
68
+ if field_names.nil?
69
+ fields = all_fields.select{|field| field.in_display_group?(display_group)}
70
+ instance_variable_set("@#{display_group}_display_field_names", fields.map{|field| field.name})
71
+ fields
72
+ else
73
+ field_names.map{|name| get_field(name)}
74
+ end
75
+ end
76
+ end
77
+ end
78
+
79
+ define_display_group_methods(display_groups)
80
+
81
+ def self.define_boolean_attribute_methods boolean_attributes
82
+
83
+ # Define methods to cache and return lists of fields & field names
84
+ # that share certain boolean characteristics (controlled, required, etc).
85
+ boolean_attributes.each do |attribute|
86
+ # Skip any attribute we have a custom method for
87
+ next if [:work_title].include? attribute
88
+ define_method("#{attribute}_fields".to_sym) do
89
+ @fields.values.select{|field| field.send("#{attribute}?".to_sym)}
90
+ end
91
+ define_method("#{attribute}_field_names".to_sym) do
92
+ field_names = send("#{attribute}_fields".to_sym).map{|field| field.name}
93
+ instance_variable_set("@#{attribute}_field_names".to_sym, field_names)
94
+ end
95
+ end
96
+ end
97
+
98
+ define_boolean_attribute_methods(boolean_attributes)
99
+
53
100
  def initialize (schema_config_path: nil, raw_schema: nil)
54
101
  schema_config_path ||= default_schema_config_path
55
102
  raw_schema ||= YAML.load_file(schema_config_path)
@@ -61,40 +108,7 @@ module ScoobySnacks
61
108
  fields
62
109
  end
63
110
  end
64
-
65
- # define methods to list display group contents
66
- display_groups.each do |display_group|
67
- define_method("#{display_group}_display_field_names") do
68
- field_names = instance_variable_get("@#{display_group}_display_field_names")
69
- if field_names.nil?
70
- send("#{display_group}_display_fields".to_sym).map{|field| field.name}
71
- else
72
- field_names
73
- end
74
- end
75
- define_method("#{display_group}_display_fields") do
76
- field_names = instance_variable_get("@#{display_group}_display_field_names")
77
- return field_names.map{|name| get_field(name)} unless field_names.nil?
78
- fields = @fields.values.select{|field| field.in_display_group?(display_group)}
79
- instance_variable_set("@#{display_group}_display_field_names", fields.map{|field| field.name})
80
- return fields
81
- end
82
- end
83
-
84
- # Define methods to cache and return lists of fields & field names
85
- # that share certain boolean characteristics (controlled, required, etc).
86
- boolean_attributes.each do |attribute|
87
- # Skip any attribute we have a custom method for
88
- next if [:work_title].include? attribute
89
- define_method("#{attribute}_fields".to_sym) do
90
- @fields.values.select{|field| field.send("#{attribute}?".to_sym)}
91
- end
92
- define_method("#{attribute}_field_names".to_sym) do
93
- field_names = send("#{attribute}_fields".to_sym).map{|field| field.name}
94
- instance_variable_set("@#{attribute}_field_names".to_sym, field_names)
95
- end
96
- end
97
-
111
+
98
112
  def get_field(name)
99
113
  @fields[name.to_s] || @fields[label_map[name.to_s]]
100
114
  end
@@ -44,13 +44,18 @@ module ScoobySnacks::SolrBehavior
44
44
 
45
45
  class Date
46
46
  # @return [Date]
47
- def self.coerce(input)
48
- field = String.coerce(input)
49
- return if field.blank?
50
- begin
51
- ::Date.parse(field)
52
- rescue ArgumentError
53
- Rails.logger.info "Unable to parse date: #{field.first.inspect}"
47
+ def self.coerce(inputs)
48
+ ::Array.wrap(inputs).reject{|input| input.blank?}.map do |input|
49
+ field = String.coerce(input)
50
+ begin
51
+ if (field.to_i.to_s == field) && (field.to_i < 3000)
52
+ ::Date.new(field.to_i)
53
+ else
54
+ ::Date.parse(field)
55
+ end
56
+ rescue ArgumentError
57
+ Rails.logger.info "Unable to parse date: #{field.inspect}"
58
+ end
54
59
  end
55
60
  end
56
61
  end
@@ -1,3 +1,3 @@
1
1
  module ScoobySnacks
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scooby_snacks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - UCSC Library Digital Initiatives Department, Ned Henry
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-02 00:00:00.000000000 Z
11
+ date: 2019-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler