igneus / calendarium-romanum

liturgical calendar library (Roman Catholic, post-Vatican II)
50 stars 21 forks source link

Undefined method `size` for some dates #10

Closed simonszu closed 6 years ago

simonszu commented 6 years ago

I have begun with implementing range querying for the CLI command. During testing i have noticed that some dates throw an exception when querying.

Some examples:

$ calendariumrom query 2017-12-03                                                                                                                                                      [15:35:11]
2017-12-03                                                 
season: Advent                                             

/home/simonszu/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/calendarium-romanum-0.4.0/lib/calendarium-romanum/cli.rb:37:in `block in query': undefined method `size' for nil:NilClass (NoMethodError)                                        
        from /home/simonszu/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/calendarium-romanum-0.4.0/lib/calendarium-romanum/cli.rb:37:in `collect'                                                                                            
        from /home/simonszu/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/calendarium-romanum-0.4.0/lib/calendarium-romanum/cli.rb:37:in `query'                                                                                              
        from /home/simonszu/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run' 
        from /home/simonszu/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'                                                                                                          
        from /home/simonszu/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'   
        from /home/simonszu/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/thor-0.20.0/lib/thor/base.rb:466:in `start' 
        from /home/simonszu/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/calendarium-romanum-0.4.0/bin/calendariumrom:6:in `<top (required)>'                                                                                                
        from /home/simonszu/.rbenv/versions/2.4.1/bin/calendariumrom:22:in `load'                                      
        from /home/simonszu/.rbenv/versions/2.4.1/bin/calendariumrom:22:in `<main>'     

The same thing happens for example on 2016-12-04, 2015-12-06, etc, this is the first (second?) advent in each year. I am not familiar with the data format of the underlying sanctorale file, so i cannot fix it myself but open this issue for now.

igneus commented 6 years ago

The error seems to originate in some code which you wrote and I can't see, so I can't help you. If you need help understanding what's going on in the code, probably most convenient is to open a PR and mark it with "[WIP]" (work in progress, not intended to be merged yet) in the title.

simonszu commented 6 years ago

The error seems to originate in some code which you wrote and I can't see

No, it doesn't. I have double checked if this issue appears in master as well. This is the line where it occurs. https://github.com/igneus/calendarium-romanum/blob/master/lib/calendarium-romanum/cli.rb#L37

igneus commented 6 years ago

Ouch, you are right and I see what's the problem: some ranks (the most prominent ones) don't have #short_desc defined. The line should be changed to

rank_length = day.celebrations.collect {|c| c.rank.short_desc.size || '' }.max
igneus commented 6 years ago

don't have #short_desc defined.

It's actually not true. In such cases #short_desc is, of course, defined (all ranks are instances of the same class Rank), but it returns nil.

simonszu commented 6 years ago

OK, great. I am rewriting the query method anyways, so i think i can implement this as well in a single PR. But not before monday... ;)

On Fri, Oct 6, 2017, 16:42 Jakub Pavlík notifications@github.com wrote:

Ouch, you are right and I see what's the problem: some ranks (the most prominent ones) don't have #short_desc defined. The line should be changed to

rank_length = day.celebrations.collect {|c| c.rank.short_desc.size || '' }.max

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/igneus/calendarium-romanum/issues/10#issuecomment-334775170, or mute the thread https://github.com/notifications/unsubscribe-auth/AAqxI0w7dGYOOMhycsx9ReQ3w5bEG3B-ks5spjxvgaJpZM4Pwf0X .

-- Before printing this email, think if it is really needed.