<commit_before>module LbccHelper
    include BlacklightHelper
    include ActionView::Helpers::TextHelper
    require 'nokogiri'
    require 'open-uri'
    require 'uri'

    def show_all_formats?
        return request.parameters[:show_articles] == 'true' ? true : false
    end

    def show_only_articles?
        return request.parameters[:show_articles] == 'only' ? true : false
    end

    def display_access_options(document, context)
    # Context options: show (individual record), index (search results)
        style = ('index' == context) ? 'simple' : 'fancy'
        if document.has? 'eg_tcn_t'
            tcn_value = render_index_field_value(:document => document, :field => 'eg_tcn_t')
            display_library_holdings(tcn_value, style)
        elsif document.has? 'url_fulltext_display'
            url_value = render_index_field_value(:document => document, :field => 'url_fulltext_display')
            display_fulltext_access_link(url_value, style)
        end
    end


    def display_fulltext_access_link(url_value, style)
        access_link = <<-EOS
          <a href=#{url_value} class="btn btn-success" role="button" target="_blank">Access this resource</a>
        EOS
        return access_link.html_safe
    end

    def snippet opts={}
	value = options[:value].join(' ')
        return truncate strip(value), length: 200, separator: ' '
    end

    def strip(string)
        # Also strip preceeding [ or whitespace
        string.gsub!(/^[\*\s]*/, '')
        string.gsub!(/[,\-:;\s]*$/, '')
        return string
    end


end<commit_msg>fixing problems with snippet helper method<commit_after>module LbccHelper
    include BlacklightHelper
    include ActionView::Helpers::TextHelper
    require 'nokogiri'
    require 'open-uri'
    require 'uri'

    def show_all_formats?
        return request.parameters[:show_articles] == 'true' ? true : false
    end

    def show_only_articles?
        return request.parameters[:show_articles] == 'only' ? true : false
    end

    def display_access_options(document, context)
    # Context options: show (individual record), index (search results)
        style = ('index' == context) ? 'simple' : 'fancy'
        if document.has? 'eg_tcn_t'
            tcn_value = render_index_field_value(:document => document, :field => 'eg_tcn_t')
            display_library_holdings(tcn_value, style)
        elsif document.has? 'url_fulltext_display'
            url_value = render_index_field_value(:document => document, :field => 'url_fulltext_display')
            display_fulltext_access_link(url_value, style)
        end
    end


    def display_fulltext_access_link(url_value, style)
        access_link = <<-EOS
          <a href=#{url_value} class="btn btn-success" role="button" target="_blank">Access this resource</a>
        EOS
        return access_link.html_safe
    end

    def snippet opts={}
	    value = opts[:value]
        return truncate strip(value), length: 200, separator: ' '
    end

    def strip(string)
        # Also strip preceeding [ or whitespace
	if !string.is_a? String
	   string = string.to_s
	end
        string.gsub!(/^[\*\s]*/, '')
        string.gsub!(/[,\-:;\s]*$/, '')
        return string
    end


end
{'fraction_non_alphanumeric': 0.11341803532692904, 'fraction_numerical': 0.0018593120545398203, 'mean_word_length': 2.865868263473054, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4522307', 'n_tokens_mistral': 1006, 'n_tokens_neox': 966, 'n_words': 226}