lib/twitter_cldr/formatters/calendars/date_time_formatter.rb
File date_time_formatter.rb
has 304 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
require 'tzinfo'
module TwitterCldr
module Formatters
class DateTimeFormatter < Formatter
Class DateTimeFormatter
has 25 methods (exceeds 20 allowed). Consider refactoring. Open
Open
class DateTimeFormatter < Formatter
WEEKDAY_KEYS = [:sun, :mon, :tue, :wed, :thu, :fri, :sat].freeze
METHODS = { # ignoring u, l, g, j, A
Method hour
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
Open
def hour(time, pattern, length, options = {})
hour = time.hour
hour = case pattern[0, 1]
when 'h' # [1-12]
hour > 12 ? (hour - 12) : (hour == 0 ? 12 : hour)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method week_fields_for
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
def week_fields_for(date)
week_data_cache[date] ||= begin
eyear = date.year
day_of_week = date.wday + 1
day_of_year = date.yday
Method era
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
Open
def era(date, pattern, length, options = {})
choices = case length
when 0
["", ""]
when 1..3
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"