Class: Capybara::BootstrapDatepicker::Picker

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara-bootstrap-datepicker.rb

Overview

The Picker class interacts with the datepicker

Instance Method Summary collapse

Constructor Details

#initializePicker

Initializes the picker



61
62
63
# File 'lib/capybara-bootstrap-datepicker.rb', line 61

def initialize
  @element = find_picker
end

Instance Method Details

#find_day(value) ⇒ Object

Get the day we want to click on

Parameters:

  • value (Fixnum)

    the day of the desired date

Returns:

  • the DOM element to click on



96
97
98
99
100
101
102
103
104
# File 'lib/capybara-bootstrap-datepicker.rb', line 96

def find_day(value)
  day_xpath = "      .//*[contains(concat(' ', @class, ' '), ' day ')\n      and not(contains(concat(' ', @class, ' '), ' old '))\n      and not(contains(concat(' ', @class, ' '), ' new '))\n      and normalize-space(text())='\#{value}']\n  eos\n  days.find :xpath, day_xpath\nend\n"

#find_month(value) ⇒ Object

Get the month we want to click on

Parameters:

  • value (Fixnum)

    the month of the desired date

Returns:

  • the DOM element to click on



89
90
91
# File 'lib/capybara-bootstrap-datepicker.rb', line 89

def find_month(value)
  months.find ".month:nth-child(#{value})"
end

#find_year(value) ⇒ Object

Get the year we want to click on

Parameters:

  • value (Fixnum)

    the year of the desired date

Returns:

  • the DOM element to click on



82
83
84
# File 'lib/capybara-bootstrap-datepicker.rb', line 82

def find_year(value)
  years.find '.year', text: value
end

#goto_decade_panelObject

Reveals the decade panel



66
67
68
69
# File 'lib/capybara-bootstrap-datepicker.rb', line 66

def goto_decade_panel
  current_month.click if days.visible?
  current_year.click if months.visible?
end

Navigates through the decade panels until the correct one

Parameters:

  • value (Fixnum)

    the year of the desired date



73
74
75
76
77
# File 'lib/capybara-bootstrap-datepicker.rb', line 73

def navigate_through_decades(value)
  decade_start, decade_end = current_decade_minmax
  goto_prev_decade(value, decade_start) if value < decade_start
  goto_next_decade(decade_end, value) if value > decade_end
end