Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MardownChecklist2Hash implementation #1

Open
stevo opened this issue Sep 5, 2018 · 8 comments
Open

MardownChecklist2Hash implementation #1

stevo opened this issue Sep 5, 2018 · 8 comments

Comments

@stevo
Copy link

stevo commented Sep 5, 2018

ruby ~/Downloads/result.rb {url} ->

"{:"Working with GIT using CLI"=>{:total=>17, :checked=>15}, :"Ruby core and stdlib"=>{:total=>150, :checked=>111, :_total=>1}, :Rails=>{:ActiveSupport=>{:total=>81, :checked=>19}}, :"Core rails skills"=>{:ActiveRecord=>{:total=>125, :checked=>112}, :"Views and Forms"=>{:total=>22, :checked=>13}, :ActionController=>{:total=>22, :checked=>13}, :Routing=>{:total=>25, :checked=>11}, :I18n=>{:total=>9, :checked=>0}, :"Action Mailer"=>{:total=>10, :checked=>6}, :"Active Job and Sidekiq"=>{:total=>11, :checked=>7}, :"Active Storage"=>{:total=>7, :checked=>0}, :"Action Cable"=>{:total=>2, :checked=>1}, :Testing=>{:total=>48, :checked=>37}}, :Patterns=>{:total=>21, :checked=>19}, :Other=>{:total=>21, :checked=>14}, :"Gems and Libraries"=>{:Development=>{:total=>19, :checked=>12}, :Testing=>{:total=>9, :checked=>7}}, :Tooling=>{:total=>5, :checked=>3}}"

"{:"Ruby core and stdlib"=>{:total=>152, :checked=>0, :small_blue_diamond_total=>22, :small_orange_diamond_total=>13, :small_red_triangle_total=>8, :_total=>1}, :ActiveSupport=>{:total=>88, :checked=>0, :small_orange_diamond_total=>11, :small_red_triangle_total=>6, :small_blue_diamond_total=>7}}"

Cover this behavior with tests

@stevo
Copy link
Author

stevo commented Sep 5, 2018

  • Nesting of headers
  • Total vs Checked
  • Classification (emojis)

@stevo stevo changed the title MardownCheclist2Hash implementation MardownChecklist2Hash implementation Sep 5, 2018
@stevo
Copy link
Author

stevo commented Sep 5, 2018

require 'rails_helper'

RSpec.describe MarkdownChecklist do
  describe '#each' do
    context 'when there are no checklist items in source' do
      it 'yields noting' do
        source = <<~MARKDOWN
          some markdown without checklist items
        MARKDOWN

        markdown_checklist = MarkdownChecklist.new(source)

        expect { |b| markdown_checklist.each(&b) }.not_to yield_control
      end
    end

    context 'when there checklist items in source' do
      context 'when there was no header specified before checklist items' do
        it 'yields summary of total and checked items for "nil" subject' do
          source = <<~MARKDOWN
            [ ] Item one
            [x] Item two
          MARKDOWN

          markdown_checklist = MarkdownChecklist.new(source)

          expect { |b| markdown_checklist.each(&b) }.to \
            yield_with_args(nil, { total: 2, checked: 1 })
        end
      end
    end
  end
end

#
# mc = MarkdownChecklist.new('markdown')
#
# 
# yield_successive_args([:a, :b], [:c, :d]) }
# 
# expect { |b| markdown_checklist.each(&b) }.to \
#             yield_successive_args([nil, { total: 2, checked: 1 }], ["GIT", { total: 2, checked: 5 }])
# 
# 
# ##
# [ ]
# [x]
#
# ##
# #
# # []
# mc.each do |subject, stats|
#   # subject: "Working with GIT using CLI"
#   # stats: { :total => 17, :checked => 15 }
#   #
#   #
#   #   # subject: nil
#   #   # stats: { :total => 17, :checked => 15 }
#   #
#   # subject: "Gems and Libraries -> Testing"
#   # stats: {:total=>9, :checked=>7}
#   # subject: "Gems and Libraries -> Development"
#   # stats: {:total=>9, :checked=>7}
# end

@stevo
Copy link
Author

stevo commented Sep 5, 2018

spec/lib/markdown_checklist_spec.rb

@stevo
Copy link
Author

stevo commented Sep 5, 2018

# mc.each do |subject, stats|
#   # subject: ["Working with GIT using CLI"]
#   # items: { 'Not nice :blue_diamond:' => false, 'Nice' => true }
#   #
#   #
#   #   # subject: [nil]
#   #   # stats: { :total => 17, :checked => 15 }
#   #

@stevo
Copy link
Author

stevo commented Sep 5, 2018

\s*#+\s*(?<subject>.*) -> Headers
	\s*\[[x\s]]\s*(?<item>.*) -> Items
	 '   [x] jasjdjasdjsd  '.match(/\s*\[[x\s]]\s*(?<item>.*)/)[:item]

@stevo
Copy link
Author

stevo commented Sep 5, 2018

\s*\[(?<checked>[x\s])]\s*(?<item>.*)

@stevo
Copy link
Author

stevo commented Sep 5, 2018

" ### aaa"=~ /\s*\#{2,}/

@stevo
Copy link
Author

stevo commented Sep 5, 2018

pseudocode

items = {}
subjects = []

get_line
	parse_line
	if line is item
	  store item and its status in "current_items"
	elsif line is subject (##+)?
		check if there are any items in buffer
			if yes
				yield current subjects and items
				clean all items from buffer
				
		if subject nesting is > current subjects
			add subject to current subjects
		elsif subject nesting is equal to current subjects
			replace last subject from current subjects with one at hand
		else
			trim current subjects to level of subject at hand and replace as above
		end

if anything is left in items
	yield current subjects and items		

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant