lib/alexandria/smart_library.rb in alexandria-book-collection-manager-0.6.9 vs lib/alexandria/smart_library.rb in alexandria-book-collection-manager-0.7.0
- old
+ new
@@ -30,15 +30,15 @@
ANY_RULE = 2
attr_reader :name
attr_accessor :rules, :predicate_operator_rule, :deleted_books
DIR = File.join(ENV['HOME'], '.alexandria', '.smart_libraries')
- EXT = '.yaml'
+ EXT = '.yaml'.freeze
def initialize(name, rules, predicate_operator_rule)
super()
- raise if name.nil? or rules.nil? or predicate_operator_rule.nil?
+ raise if name.nil? || rules.nil? || predicate_operator_rule.nil?
@name = name
@rules = rules
@predicate_operator_rule = predicate_operator_rule
save
libraries = Libraries.instance
@@ -160,11 +160,11 @@
def refilter
raise 'need libraries' if @libraries.nil?
raise 'no libraries' if @libraries.empty?
raise 'need predicate operator' if @predicate_operator_rule.nil?
- raise 'need rule' if @rules.nil? or @rules.empty?
+ raise 'need rule' if @rules.nil? || @rules.empty?
filters = @rules.map(&:filter_proc)
selector = @predicate_operator_rule == ALL_RULES ? :all? : :any?
clear
@@ -175,11 +175,11 @@
filters.send(selector) { |filter| filter.call(book) } # Problem here.
end
filtered_library.each { |x| @cache[x] = library }
concat(filtered_library)
end
- @n_rated = count { |x| !x.rating.nil? and x.rating > 0 }
+ @n_rated = count { |x| !x.rating.nil? && x.rating > 0 }
end
def cover(book)
@cache[book].cover(book)
end
@@ -194,11 +194,11 @@
def save(book = nil)
if book
@cache[book].save(book)
else
- FileUtils.mkdir_p(DIR)
+ FileUtils.mkdir_p(DIR) unless File.exist? DIR
File.open(yaml, 'w') { |io| io.puts to_hash.to_yaml }
end
end
def save_cover(book, _cover_uri)
@@ -279,11 +279,11 @@
bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
attr_accessor :operand, :operation, :value
def initialize(operand, operation, value)
- raise if operand.nil? or operation.nil? # value can be nil
+ raise if operand.nil? || operation.nil? # value can be nil
@operand = operand
@operation = operation
@value = value
end
@@ -393,19 +393,19 @@
IS_LESS_THAN = Operator.new(:is_less_than,
_('is less than'),
proc { |x, y| x < y })
IS_AFTER = Operator.new(:is_after,
_('is after'),
- proc { |x, y| x.to_i > y.to_i and !x.nil? })
+ proc { |x, y| x.to_i > y.to_i && !x.nil? })
IS_BEFORE = Operator.new(:is_before,
_('is before'),
- proc { |x, y| x.to_i < y.to_i and !x.nil? })
+ proc { |x, y| x.to_i < y.to_i && !x.nil? })
IS_IN_LAST = Operator.new(:is_in_last_days,
_('is in last'),
proc { |x, y|
begin
- if x.nil? or x.empty?
+ if x.nil? || x.empty?
false
else
log.debug { "Given Date: #{x.inspect} #{x.class}" }
given_date = Time.parse(x)
days = y.to_i * (24 * 60 * 60)
@@ -420,11 +420,11 @@
})
IS_NOT_IN_LAST = Operator.new(:is_not_in_last_days,
_('is not in last'),
proc { |x, y|
begin
- if x.nil? or x.empty?
+ if x.nil? || x.empty?
false
else
log.debug { "Given Date: #{x.inspect} #{x.class}" }
given_date = Time.parse(x)
days = y.to_i * (24 * 60 * 60)
@@ -489,11 +489,11 @@
INTEGER_OPERATORS.map { |x| [x, Operands::INTEGER] }
when 'TrueClass'
BOOLEAN_OPERATORS.map { |x| [x, nil] }
when 'Time'
TIME_OPERATORS.map do |x|
- if x == Operators::IS_IN_LAST or
- x == Operators::IS_NOT_IN_LAST
+ if (x == Operators::IS_IN_LAST) ||
+ (x == Operators::IS_NOT_IN_LAST)
[x, Operands::DAYS]
else
[x, Operands::TIME]
end